libacfutils
A general purpose library of utility functions designed to make it easier to develop addons for the X-Plane flight simulator.
|
#include "types.h"
Go to the source code of this file.
Macros | |
#define | NO_ACF_TYPE 0 |
#define | FF_A320_ACF_TYPE 1 |
#define | DIRSEP '/' |
#define | DIRSEP_S "/" /* DIRSEP as a string */ |
#define | MAX_PATH 512 |
#define | DEPRECATED_ATTR |
#define | PRINTF_ATTR(x) |
#define | PRINTF_ATTR2(x, y) |
#define | SENTINEL_ATTR |
#define | HOT_ATTR |
#define | PURE_ATTR |
#define | ALWAYS_INLINE_ATTR |
#define | COND_LIKELY(x) x |
#define | COND_UNLIKELY(x) x |
#define | ALIGN_ATTR(x) |
#define | PRINTF_FORMAT(f) f |
#define | BSWAP16(x) |
#define | BSWAP32(x) |
#define | BSWAP64(x) |
#define | BE64(x) (x) |
#define | BE32(x) (x) |
#define | BE16(x) (x) |
#define | DESTROY(x) do { free(x); (x) = NULL; } while (0) |
#define | DESTROY_OP(var, zero_val, destroy_op) |
#define | PATHSEP "/" |
#define | MIN_ELEV -2000.0 |
#define | MAX_ELEV 30000.0 |
#define | MIN_ALT -2000.0 |
#define | MAX_ALT 100000.0 |
#define | MAX_SPD 1000.0 |
#define | MIN_ARC_RADIUS 0.1 |
#define | MAX_ARC_RADIUS 100.0 |
#define | TYPE_ASSERT(x, type) |
#define | NOT_TYPE_ASSERT(x, type) |
#define | CTASSERT(x) |
#define | MIN(x, y) ((x) < (y) ? (x) : (y)) |
#define | MAX(x, y) ((x) > (y) ? (x) : (y)) |
#define | AVG(x, y) (((x) + (y)) / 2.0) |
#define | FILTER_IN_TYPE(x) __typeof__(x) |
#define | FILTER_IN(old_val, new_val, d_t, lag) |
#define | FILTER_IN_NAN(old_val, new_val, d_t, lag) |
#define | FILTER_IN_LIN(old_val, tgt, d_t, step) |
#define | SCANF_STR_AUTOLEN_IMPL(_str_) #_str_ |
#define | SCANF_STR_AUTOLEN(_str_) SCANF_STR_AUTOLEN_IMPL(_str_) |
#define | REQ_PTR(x) *x |
#define | REQ_ARR(x) x[n] |
#define | ENUM_BIT_WIDTH_CHECK(enum_type, num_bits, ...) |
Compile-time macro for checking whether an enum can be represented in a fixed number of bits. | |
#define ALIGN_ATTR | ( | x | ) |
Definition at line 93 of file sysmacros.h.
#define ALWAYS_INLINE_ATTR |
Definition at line 85 of file sysmacros.h.
#define AVG | ( | x, | |
y | |||
) | (((x) + (y)) / 2.0) |
Definition at line 228 of file sysmacros.h.
#define BE16 | ( | x | ) | (x) |
Definition at line 132 of file sysmacros.h.
#define BE32 | ( | x | ) | (x) |
Definition at line 131 of file sysmacros.h.
#define BE64 | ( | x | ) | (x) |
Definition at line 130 of file sysmacros.h.
#define BSWAP16 | ( | x | ) |
Definition at line 109 of file sysmacros.h.
#define BSWAP32 | ( | x | ) |
Definition at line 112 of file sysmacros.h.
#define BSWAP64 | ( | x | ) |
Definition at line 117 of file sysmacros.h.
#define COND_LIKELY | ( | x | ) | x |
Definition at line 87 of file sysmacros.h.
#define COND_UNLIKELY | ( | x | ) | x |
Definition at line 88 of file sysmacros.h.
#define CTASSERT | ( | x | ) |
Definition at line 191 of file sysmacros.h.
#define DEPRECATED_ATTR |
Definition at line 79 of file sysmacros.h.
#define DESTROY | ( | x | ) | do { free(x); (x) = NULL; } while (0) |
Definition at line 139 of file sysmacros.h.
#define DESTROY_OP | ( | var, | |
zero_val, | |||
destroy_op | |||
) |
Definition at line 140 of file sysmacros.h.
#define DIRSEP '/' |
Definition at line 49 of file sysmacros.h.
#define DIRSEP_S "/" /* DIRSEP as a string */ |
Definition at line 50 of file sysmacros.h.
#define ENUM_BIT_WIDTH_CHECK | ( | enum_type, | |
num_bits, | |||
... | |||
) |
Compile-time macro for checking whether an enum can be represented in a fixed number of bits.
This macro lets you perform a simple compile-time check to validate that all variants of an enum fit into a fixed bit space representation. This way you can validate that no variant accidentally exceeds the amount of bit space allocated in a bit field.
This macro is used in conjunction with the ENUM_BIT_WIDTH_CHECK_VARIANT macro as follows:
This macro performs no runtime computation and thus is complete inert from a runtime standpoint. All checking is performed at compile time. While you must manually list all enum variants in the macro to perform all checks, your compiler should warn you about unhandled variants, in case you forgot some, or added some variants later.
Definition at line 415 of file sysmacros.h.
#define FF_A320_ACF_TYPE 1 |
Definition at line 43 of file sysmacros.h.
#define FILTER_IN | ( | old_val, | |
new_val, | |||
d_t, | |||
lag | |||
) |
Definition at line 244 of file sysmacros.h.
#define FILTER_IN_LIN | ( | old_val, | |
tgt, | |||
d_t, | |||
step | |||
) |
Definition at line 277 of file sysmacros.h.
#define FILTER_IN_NAN | ( | old_val, | |
new_val, | |||
d_t, | |||
lag | |||
) |
Definition at line 261 of file sysmacros.h.
#define FILTER_IN_TYPE | ( | x | ) | __typeof__(x) |
Definition at line 233 of file sysmacros.h.
#define HOT_ATTR |
Definition at line 83 of file sysmacros.h.
#define MAX | ( | x, | |
y | |||
) | ((x) > (y) ? (x) : (y)) |
Definition at line 225 of file sysmacros.h.
#define MAX_ALT 100000.0 |
Definition at line 160 of file sysmacros.h.
#define MAX_ARC_RADIUS 100.0 |
Definition at line 167 of file sysmacros.h.
#define MAX_ELEV 30000.0 |
Definition at line 156 of file sysmacros.h.
#define MAX_PATH 512 |
Definition at line 52 of file sysmacros.h.
#define MAX_SPD 1000.0 |
Definition at line 163 of file sysmacros.h.
#define MIN | ( | x, | |
y | |||
) | ((x) < (y) ? (x) : (y)) |
Definition at line 222 of file sysmacros.h.
#define MIN_ALT -2000.0 |
Definition at line 159 of file sysmacros.h.
#define MIN_ARC_RADIUS 0.1 |
Definition at line 166 of file sysmacros.h.
#define MIN_ELEV -2000.0 |
Definition at line 155 of file sysmacros.h.
#define NO_ACF_TYPE 0 |
Definition at line 42 of file sysmacros.h.
#define NOT_TYPE_ASSERT | ( | x, | |
type | |||
) |
Definition at line 183 of file sysmacros.h.
#define PATHSEP "/" |
Definition at line 151 of file sysmacros.h.
#define PRINTF_ATTR | ( | x | ) |
Definition at line 80 of file sysmacros.h.
#define PRINTF_ATTR2 | ( | x, | |
y | |||
) |
Definition at line 81 of file sysmacros.h.
#define PRINTF_FORMAT | ( | f | ) | f |
Definition at line 105 of file sysmacros.h.
#define PURE_ATTR |
Definition at line 84 of file sysmacros.h.
#define REQ_ARR | ( | x | ) | x[n] |
Same as REQ_PTR(), except allows specifying a number of elements in a fixed-size array. This will allow you to treat the pointer as an array while letting the compiler perform static bounds checking where possible. If the caller passes a fixed-size array, the compiler will also perform bounds checking on the calling side.
The way to use this macro is as follows:
This declares a pointer argument named arg
to be a non-NULL'able reference to an array of at least 5 elements. When compiling for C11 or higher, this expands into:
Please note that this doesn't imply any kind of runtime bounds checks. If you use a runtime variable to perform array indexing, this is still not guaranteed to catch out-of-bounds array access bugs.
Another method to use this macro is to pass a dynamic size, such as:
This lets the callee accept variable-length arrays, while still letting the caller perform compile-time bounds checks, such that a mismatched size argument and actual static array size can be detected and flagged. Once again, this doesn't provide dynamic bounds checks, so its function is simply to serve as additional type annotations for checks which can be performed at compile time.
Definition at line 375 of file sysmacros.h.
#define REQ_PTR | ( | x | ) | *x |
Marks a pointer argument as a required (i.e. non-NULL'able). This uses C11's [static 1]
syntax to declare a pointer, which must point to allocated memory. The way to use this macro is as follows:
This declares a pointer argument named arg
to be non-NULL'able. When compiling for C11 or higher, this expands into:
The code in the function can then manipulate this pointer as more-or-less a normal pointer, with the exception that you may not call free()
on it, as that violates the guarantee that the pointer always point to allocated memory. The code may, however, freely read and write to the object. There is an additional constraint, in that the compiler now treats this as a pointer to a single object, rather than an indexable array. To declare a non-NULL'able pointer to an array of known size, use the REQ_ARR() macro.
If the caller doesn't support C11 constructs (e.g. it is C++ or Rust), this macro expands to a plain pointer, so this safety aspect is only available for C11 or newer code.
Please also note that this doesn't guarantee that there is no combination of factors possible where this pointer may be NULL even in pure C11 code. If the caller is simply passing through a plain pointer from their own arguments (the caller function just serving as an intermediary), then the ultimate origin of the pointer might still have passed NULL. For this guarantee to hold fully, all code up the stack would need to support C11 constructs and/or provide rubust integrity checks against stray NULLs.
Definition at line 334 of file sysmacros.h.
#define SCANF_STR_AUTOLEN | ( | _str_ | ) | SCANF_STR_AUTOLEN_IMPL(_str_) |
Definition at line 295 of file sysmacros.h.
#define SCANF_STR_AUTOLEN_IMPL | ( | _str_ | ) | #_str_ |
Definition at line 294 of file sysmacros.h.
#define SENTINEL_ATTR |
Definition at line 82 of file sysmacros.h.
#define TYPE_ASSERT | ( | x, | |
type | |||
) |
Definition at line 182 of file sysmacros.h.