BRL-CAD
common.h (Common Definitions)

Files

file  common.h
 Header file for the BRL-CAD common definitions.
 

Macros

#define FMAX(a, b)   (((a)>(b))?(a):(b))
 
#define FMIN(a, b)   (((a)<(b))?(a):(b))
 
#define _FILE_OFFSET_BITS   64
 
#define b_off_t   off_t
 
#define MAXPATHLEN   2048
 
#define GCC_PREREQ(major, minor)   0
 
#define ICC_PREREQ(version)   0
 
#define __attribute__(ignore)   /* empty */
 
#define __format__   format
 
#define __printf__   printf
 
#define __noreturn__   noreturn
 
#define always_inline   noinline
 
#define UNUSED(parameter)   /* parameter */
 
#define LIKELY(expression)   (expression)
 
#define UNLIKELY(expression)   (expression)
 
#define DEPRECATED   /* deprecated */
 
#define NORETURN   /* does not return */
 
#define FAUX_NORETURN   /* pretend does not return */
 
#define __STDC_VERSION__   0
 
#define EXTERNVARINIT   extern
 
#define CPP_STR(x)   # x
 
#define CPP_XSTR(x)   CPP_STR(x)
 
#define CPP_GLUE(a, b)   a ## b
 
#define CPP_XGLUE(a, b)   CPP_GLUE(a, b)
 
#define CPP_SCAN(sz)   "%" CPP_XSTR(sz) "s"
 
#define CPP_FILELINE   __FILE__ ":" CPP_XSTR(__LINE__)
 
#define COMPILER_DLLEXPORT
 
#define COMPILER_DLLIMPORT
 

Detailed Description

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.

Macro Definition Documentation

◆ FMAX

#define FMAX (   a,
 
)    (((a)>(b))?(a):(b))

Find and return the maximum value

Definition at line 132 of file common.h.

◆ FMIN

#define FMIN (   a,
 
)    (((a)<(b))?(a):(b))

Find and return the minimum value

Definition at line 136 of file common.h.

◆ _FILE_OFFSET_BITS

#define _FILE_OFFSET_BITS   64

Definition at line 153 of file common.h.

◆ b_off_t

#define b_off_t   off_t

make sure ssize_t is provided. C99 does not provide it even though it is defined in SUS97. if not available, we create the type aligned with the similar POSIX ptrdiff_t type.

Definition at line 222 of file common.h.

◆ MAXPATHLEN

#define MAXPATHLEN   2048

Maximum length of a filesystem path. Typically defined in a system file but if it isn't set, we create it.

Definition at line 238 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 262 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 286 of file common.h.

◆ __attribute__

#define __attribute__ (   ignore)    /* empty */

Definition at line 295 of file common.h.

◆ __format__

#define __format__   format

Definition at line 301 of file common.h.

◆ __printf__

#define __printf__   printf

Definition at line 302 of file common.h.

◆ __noreturn__

#define __noreturn__   noreturn

Definition at line 303 of file common.h.

◆ always_inline

#define always_inline   noinline

Definition at line 311 of file common.h.

◆ 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 334 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 358 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 379 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 400 of file common.h.

◆ NORETURN

#define NORETURN   /* does not return */

NORETURN declares that a function does not return.

For portability, the attribute must precede the function, i.e., be declared on the left:

NORETURN void function(void);

Note that throwing an exception or calling longjmp() do not constitute a return. Functions that (always) infinite loop can be considered functions that do not return. Functions that do not return should have a void return type. This option is a hint to compilers and static analyers, to reduce false positive reporting.

Definition at line 427 of file common.h.

◆ FAUX_NORETURN

#define FAUX_NORETURN   /* pretend does not return */

FAUX_NORETURN declares a function should be treated as if it does not return, even though it can.

As this label is (currently) Clang-specific, it can be declared on the left or right of a function declaration. Left is recommended for consistency with other annotations, e.g.:

FAUX_NORETURN void function(void);

This annocation is almost identical to NORETURN except that it does not affect code generation and can be used on functions that actually return. It's typically useful for annotating assertion handlers (e.g., assert()) that sometimes return and should not be used on NORETURN functions. This annotation is primarily a hint to static analyzers.

Definition at line 455 of file common.h.

◆ __STDC_VERSION__

#define __STDC_VERSION__   0

Definition at line 472 of file common.h.

◆ 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 538 of file common.h.

◆ CPP_STR

#define CPP_STR (   x)    # x

Provide canonical preprocessor stringification.

#define abc 123
CPP_STR(abc) => "abc"
#define CPP_STR(x)
Definition: common.h:552

Definition at line 552 of file common.h.

◆ CPP_XSTR

#define CPP_XSTR (   x)    CPP_STR(x)

Provide canonical preprocessor expanded stringification.

#define abc 123
CPP_XSTR(abc) => "123"
#define CPP_XSTR(x)
Definition: common.h:564

Definition at line 564 of file common.h.

◆ CPP_GLUE

#define CPP_GLUE (   a,
 
)    a ## b

Provide canonical preprocessor concatenation.

#define abc 123
CPP_GLUE(abc, 123) => abc123
CPP_STR(CPP_GLUE(abc, 123)) => "CPP_GLUE(abc, 123)"
CPP_XSTR(CPP_GLUE(abc, 123)) => "abc123"
#define abc123 "xyz"
CPP_GLUE(abc, 123) => abc123 => "xyz"
#define CPP_GLUE(a, b)
Definition: common.h:580

Definition at line 580 of file common.h.

◆ CPP_XGLUE

#define CPP_XGLUE (   a,
 
)    CPP_GLUE(a, b)

Provide canonical preprocessor expanded concatenation.

#define abc 123
CPP_XGLUE(abc, 123) => 123123
CPP_STR(CPP_XGLUE(abc, 123)) => "CPP_XGLUE(abc, 123)"
CPP_XSTR(CPP_XGLUE(abc, 123)) => "123123"
#define CPP_XGLUE(a, b)
Definition: common.h:594

Definition at line 594 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 607 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 615 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 630 of file common.h.

◆ COMPILER_DLLIMPORT

#define COMPILER_DLLIMPORT

Definition at line 631 of file common.h.