|
file | common.h |
| Header file for the BRL-CAD common definitions.
|
|
This header wraps system and compilation-specific defines from brlcad_config.h and removes need to conditionally include brlcad_config.h everywhere based on HAVE_CONFIG_H. The common definitions are symbols common to the platform being built that are either detected via configure or hand crafted, as is the case for the win32 platform.
NOTE: In order to use compile-time API, applications need to define BRLCADBUILD and HAVE_CONFIG_H before including this header.
◆ HIDDEN
Functions local to one file IN A LIBRARY should be declared HIDDEN. Disabling the static classifier is sometimes helpful for debugging. It can help prevent some compilers from inlining functions that one might want to set a breakpoint on. Do not use on variables.
Definition at line 129 of file common.h.
◆ FMAX
#define FMAX |
( |
|
a, |
|
|
|
b |
|
) |
| (((a)>(b))?(a):(b)) |
Find and return the maximum value
Definition at line 146 of file common.h.
◆ FMIN
#define FMIN |
( |
|
a, |
|
|
|
b |
|
) |
| (((a)<(b))?(a):(b)) |
Find and return the minimum value
Definition at line 150 of file common.h.
◆ _FILE_OFFSET_BITS
#define _FILE_OFFSET_BITS 64 |
◆ b_off_t
C99 does not provide a ssize_t even though it is provided by SUS97. regardless, we use it so make sure it's declared by using the similar POSIX ptrdiff_t type.
Definition at line 231 of file common.h.
◆ MAXPATHLEN
Maximum length of a filesystem path. Typically defined in a system file but if it isn't set, we create it.
Definition at line 247 of file common.h.
◆ GCC_PREREQ
#define GCC_PREREQ |
( |
|
major, |
|
|
|
minor |
|
) |
| 0 |
Provide a means to conveniently test the version of the GNU compiler. Use it like this:
#if GCC_PREREQ(2,8)
... code requiring gcc 2.8 or later ...
#endif
WARNING: THIS MACRO IS CONSIDERED PRIVATE AND SHOULD NOT BE USED OUTSIDE OF THIS HEADER FILE. DO NOT RELY ON IT.
Definition at line 271 of file common.h.
◆ ICC_PREREQ
#define ICC_PREREQ |
( |
|
version | ) |
0 |
Provide a means to conveniently test the version of the Intel compiler. Use it like this:
#if ICC_PREREQ(800)
... code requiring icc 8.0 or later ...
#endif
WARNING: THIS MACRO IS CONSIDERED PRIVATE AND SHOULD NOT BE USED OUTSIDE OF THIS HEADER FILE. DO NOT RELY ON IT.
Definition at line 295 of file common.h.
◆ __attribute__
#define __attribute__ |
( |
|
ignore | ) |
/* empty */ |
◆ __format__
#define __format__ format |
◆ __printf__
#define __printf__ printf |
◆ __noreturn__
#define __noreturn__ noreturn |
◆ always_inline
#define always_inline noinline |
◆ UNUSED
#define UNUSED |
( |
|
parameter | ) |
/* parameter */ |
UNUSED provides a common mechanism for declaring unused parameters. Use it like this:
int my_function(int argc, char **UNUSED(argv)) { ... }
Definition at line 343 of file common.h.
◆ LIKELY
#define LIKELY |
( |
|
expression | ) |
(expression) |
LIKELY provides a common mechanism for providing branch prediction hints to the compiler so that it can better optimize. It should be used when it's exceptionally likely that an expected code path will almost always be executed. Use it like this:
if (LIKELY(x == 1)) { ... expected code path ... }
Definition at line 367 of file common.h.
◆ UNLIKELY
#define UNLIKELY |
( |
|
expression | ) |
(expression) |
UNLIKELY provides a common mechanism for providing branch prediction hints to the compiler so that it can better optimize. It should be used when it's exceptionally unlikely that a given code path will ever be executed. Use it like this:
if (UNLIKELY(x == 0)) { ... unexpected code path ... }
Definition at line 388 of file common.h.
◆ DEPRECATED
#define DEPRECATED /* deprecated */ |
DEPRECATED provides a common mechanism for denoting public API (e.g., functions, typedefs, variables) that is considered deprecated. Use it like this:
DEPRECATED int my_function(void);
typedef struct karma some_type DEPRECATED;
Definition at line 409 of file common.h.
◆ __STDC_VERSION__
#define __STDC_VERSION__ 0 |
◆ EXTERNVARINIT
#define EXTERNVARINIT extern |
globally disable certain warnings. do NOT add new warnings here without discussion and research. only warnings that cannot be quieted without objectively decreasing code quality should be added! even warnings that are innocuous or produce false-positive should be quelled when possible.
any warnings added should include a description and justification. Provide a macro for different treatment of initialized extern const variables between C and C++. In C the following initialization (definition) is acceptable for external linkage:
const int var = 10;
but in C++ const is implicitly internal linkage so it must have extern qualifier:
extern const int var = 10;
Definition at line 483 of file common.h.
◆ CPP_STR
Provide canonical preprocessor stringification.
Definition at line 497 of file common.h.
◆ CPP_XSTR
Provide canonical preprocessor expanded stringification.
Definition at line 509 of file common.h.
◆ CPP_GLUE
#define CPP_GLUE |
( |
|
a, |
|
|
|
b |
|
) |
| a ## b |
Provide canonical preprocessor concatenation.
#define abc 123
#define abc123 "xyz"
Definition at line 525 of file common.h.
◆ CPP_XGLUE
#define CPP_XGLUE |
( |
|
a, |
|
|
|
b |
|
) |
| CPP_GLUE(a, b) |
Provide canonical preprocessor expanded concatenation.
Definition at line 539 of file common.h.
◆ CPP_SCAN
#define CPP_SCAN |
( |
|
sz | ) |
"%" CPP_XSTR(sz) "s" |
Provide format specifier string tied to a size (e.g., "%123s")
#define STR_LEN 10+1
char str[STR_LEN] = {0};
scanf(CPP_SCANSIZE(STR_LEN) "\n", str);
Definition at line 552 of file common.h.
◆ CPP_FILELINE
#define CPP_FILELINE __FILE__ ":" CPP_XSTR(__LINE__) |
Provide the current filename and linenumber as a static preprocessor string in "file"":""line" format (e.g., "file:123").
Definition at line 560 of file common.h.
◆ COMPILER_DLLEXPORT
#define COMPILER_DLLEXPORT |
If we've not already defined COMPILER_DLLEXPORT and COMPILER_DLLIMPORT, define them away so code including the *_EXPORT header logic won't fail.
Definition at line 575 of file common.h.
◆ COMPILER_DLLIMPORT
#define COMPILER_DLLIMPORT |