2021-07-09 00:04:44 +02:00
|
|
|
/** See the end of this file for copyright and license terms. */
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "neo/_types.h"
|
|
|
|
|
2021-07-15 22:51:24 +02:00
|
|
|
#ifdef __cplusplus
|
|
|
|
# define nil nullptr
|
|
|
|
#else
|
|
|
|
# define nil ((void *)0)
|
|
|
|
#endif
|
2021-07-09 00:04:44 +02:00
|
|
|
|
2021-07-11 01:44:59 +02:00
|
|
|
#ifndef offsetof
|
2021-07-14 20:45:22 +02:00
|
|
|
# define offsetof(type, member) __builtin_offsetof(type, member)
|
2021-07-11 01:44:59 +02:00
|
|
|
#endif
|
|
|
|
|
2021-07-15 20:59:31 +02:00
|
|
|
#ifndef typeof
|
|
|
|
# define typeof(expr) __typeof(expr)
|
|
|
|
#endif
|
|
|
|
|
2021-07-15 01:47:04 +02:00
|
|
|
/** Get the absolute (non negative) value of an integer */
|
|
|
|
#define nabs(n) ({ \
|
|
|
|
/* n is an expression, not a variable, evaluate it only once */ \
|
|
|
|
typeof(n) __neo_local_n = (n); \
|
|
|
|
__neo_local_n < 0 ? -__neo_local_n : __neo_local_n; \
|
|
|
|
})
|
|
|
|
|
2021-07-21 22:55:05 +02:00
|
|
|
#define nmax(x1, x2) ({ \
|
|
|
|
typeof(x1) __x1 = (x1); \
|
|
|
|
typeof(x2) __x2 = (x2); \
|
|
|
|
__x1 > __x2 ? __x1 : __x2; \
|
|
|
|
})
|
|
|
|
|
|
|
|
#define nmin(x1, x2) ({ \
|
|
|
|
typeof(x1) __x1 = (x1); \
|
|
|
|
typeof(x2) __x2 = (x2); \
|
|
|
|
__x1 < __x2 ? __x1 : x2; \
|
|
|
|
})
|
|
|
|
|
2021-07-11 01:44:59 +02:00
|
|
|
/**
|
2021-07-18 21:00:07 +02:00
|
|
|
* Quickly get the length (as in amount of items, not bytes) of any libneo data
|
|
|
|
* structure that supports it. This includes strings, buffers, lists, and more.
|
2021-07-11 01:44:59 +02:00
|
|
|
*
|
2021-07-18 21:00:07 +02:00
|
|
|
* @param thing: Thing to get the length of
|
|
|
|
* @returns: The length as a `const usize`
|
2021-07-11 01:44:59 +02:00
|
|
|
*/
|
|
|
|
#define nlen(thing) ((thing)->__neo_nlen)
|
2021-07-09 00:04:44 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* This file is part of libneo.
|
|
|
|
* Copyright (c) 2021 Fefie <owo@fef.moe>.
|
|
|
|
*
|
|
|
|
* libneo is non-violent software: you may only use, redistribute,
|
|
|
|
* and/or modify it under the terms of the CNPLv6+ as found in
|
|
|
|
* the LICENSE file in the source code root directory or at
|
|
|
|
* <https://git.pixie.town/thufie/CNPL>.
|
|
|
|
*
|
|
|
|
* libneo comes with ABSOLUTELY NO WARRANTY, to the extent
|
|
|
|
* permitted by applicable law. See the CNPLv6+ for details.
|
|
|
|
*/
|