BRL-CAD
common.h (Common Definitions)

Files

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

Macros

#define HIDDEN   /***/
 
#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 __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

◆ HIDDEN

#define 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,
 
)    (((a)>(b))?(a):(b))

Find and return the maximum value

Definition at line 146 of file common.h.

◆ FMIN

#define FMIN (   a,
 
)    (((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

Definition at line 167 of file common.h.

◆ b_off_t

#define b_off_t   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

#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 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 */

Definition at line 304 of file common.h.

◆ __format__

#define __format__   format

Definition at line 310 of file common.h.

◆ __printf__

#define __printf__   printf

Definition at line 311 of file common.h.

◆ __noreturn__

#define __noreturn__   noreturn

Definition at line 312 of file common.h.

◆ always_inline

#define always_inline   noinline

Definition at line 320 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 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

Definition at line 426 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 483 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:497

Definition at line 497 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:509

Definition at line 509 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:525

Definition at line 525 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:539

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

Definition at line 576 of file common.h.