KallistiOS git master
Independent SDK for the Sega Dreamcast
|
General useful language macros More...
Macros | |
#define | __build_assert(cond) do { (void) sizeof(char [1 - 2*!(cond)]); } while(0) |
Assert a build-time dependency. | |
#define | __build_assert_or_zero(cond) (sizeof(char [1 - 2*!(cond)]) - 1) |
Assert a build-time dependency. | |
#define | __array_size(arr) (sizeof(arr) / sizeof((arr)[0]) + _array_size_chk(arr)) |
Get the number of elements in a visible array. | |
#define | _array_size_chk(arr) 0 |
#define | __stringify(arg) ""#arg |
Create a string from the argument. | |
#define | __is_defined(macro) !__builtin_strcmp(__stringify(macro), "1") |
Check if a macro is defined to 1. | |
General useful language macros
This group contains definitions to help give robust solutions to common code patterns.
#define __array_size | ( | arr | ) | (sizeof(arr) / sizeof((arr)[0]) + _array_size_chk(arr)) |
Get the number of elements in a visible array.
This does not work on pointers, or arrays declared as [], or function parameters. With correct compiler support, such usage will cause a build error (
arr | The array whose size you want. |
#define __build_assert | ( | cond | ) | do { (void) sizeof(char [1 - 2*!(cond)]); } while(0) |
Assert a build-time dependency.
Your compiler will fail if the condition isn't true, or can't be evaluated by the compiler. This can only be used within a function.
Example: #include <stddef.h> ... static char *foo_to_char(struct foo *foo) { This code needs string to be at start of foo. __build_assert(offsetof(struct foo, string) == 0); return (char *)foo; }
cond | The compile-time condition which must be true. |
#define __build_assert_or_zero | ( | cond | ) | (sizeof(char [1 - 2*!(cond)]) - 1) |
Assert a build-time dependency.
Your compiler will fail if the condition isn't true, or can't be evaluated by the compiler. This can be used in an expression: its value is "0".
Example: #define foo_to_char(foo) \ ((char *)(foo) \
cond | The compile-time condition which must be true. |
#define __is_defined | ( | macro | ) | !__builtin_strcmp(__stringify(macro), "1") |
Check if a macro is defined to 1.
macro | The macro to check |
#define __stringify | ( | arg | ) | ""#arg |
Create a string from the argument.
arg | The text to stringify. |
#define _array_size_chk | ( | arr | ) | 0 |