ic-macros  0.1.5
ic_macros.h File Reference

Go to the source code of this file.

Macros

#define IC_G_ABS(x)   ((x) < 0 ? (-(x)) : (x))
 Only use in global scope; absolute value. More...
 
#define IC_ABS(x)   _IC_MAKE_SINGLE_EVAL_1(IC_G_ABS, x)
 Absolute value. More...
 
#define IC_ANSI_RED   "\x1b[31m"
 
#define IC_ANSI_GREEN   "\x1b[32m"
 
#define IC_ANSI_YELLOW   "\x1b[33m"
 
#define IC_ANSI_BLUE   "\x1b[34m"
 
#define IC_ANSI_MAGENTA   "\x1b[95m"
 
#define IC_ANSI_CYAN   "\x1b[96m"
 
#define IC_ANSI_BOLD   "\x1b[1m"
 
#define IC_ANSI_DIM   "\x1b[2m"
 
#define IC_ANSI_DIM2   "\x1b[38;5;241m"
 
#define IC_ANSI_NONE   ""
 
#define IC_ANSI_RESET   "\x1b[0m"
 
#define IC_INLINE   inline __attribute__((always_inline))
 Inline the function regardless of optimization level. More...
 
#define IC_PACK   __attribute__((packed))
 The packed attribute specifies that a variable or structure field should have the smallest possible alignment—one byte for a variable, and one bit for a field, unless you specify a larger value with the aligned attribute. More...
 
#define IC_CONST   __attribute__((const))
 Calls to functions whose return value is not affected by changes to the observable state of the program and that have no observable effects on such state other than to return a value may lend themselves to optimizations such as common subexpression elimination. Declaring such functions with the const attribute allows GCC to avoid emitting some calls in repeated invocations of the function with the same argument values. More...
 
#define IC_PURE   __attribute__((pure))
 Calls to functions that have no observable effects on the state of the program other than to return a value may lend themselves to optimizations such as common subexpression elimination. Declaring such functions with the pure attribute allows GCC to avoid emitting some calls in repeated invocations of the function with the same argument values. More...
 

Macro Definition Documentation

◆ IC_ABS

#define IC_ABS (   x)    _IC_MAKE_SINGLE_EVAL_1(IC_G_ABS, x)

Absolute value.

Returns
The absolute value of the argument.

Definition at line 36 of file ic_macros.h.

◆ IC_ANSI_BLUE

#define IC_ANSI_BLUE   "\x1b[34m"

Definition at line 41 of file ic_macros.h.

◆ IC_ANSI_BOLD

#define IC_ANSI_BOLD   "\x1b[1m"

Definition at line 44 of file ic_macros.h.

◆ IC_ANSI_CYAN

#define IC_ANSI_CYAN   "\x1b[96m"

Definition at line 43 of file ic_macros.h.

◆ IC_ANSI_DIM

#define IC_ANSI_DIM   "\x1b[2m"

Definition at line 45 of file ic_macros.h.

◆ IC_ANSI_DIM2

#define IC_ANSI_DIM2   "\x1b[38;5;241m"

Definition at line 46 of file ic_macros.h.

◆ IC_ANSI_GREEN

#define IC_ANSI_GREEN   "\x1b[32m"

Definition at line 39 of file ic_macros.h.

◆ IC_ANSI_MAGENTA

#define IC_ANSI_MAGENTA   "\x1b[95m"

Definition at line 42 of file ic_macros.h.

◆ IC_ANSI_NONE

#define IC_ANSI_NONE   ""

Definition at line 47 of file ic_macros.h.

◆ IC_ANSI_RED

#define IC_ANSI_RED   "\x1b[31m"

Definition at line 38 of file ic_macros.h.

◆ IC_ANSI_RESET

#define IC_ANSI_RESET   "\x1b[0m"

Definition at line 48 of file ic_macros.h.

◆ IC_ANSI_YELLOW

#define IC_ANSI_YELLOW   "\x1b[33m"

Definition at line 40 of file ic_macros.h.

◆ IC_CONST

#define IC_CONST   __attribute__((const))

Calls to functions whose return value is not affected by changes to the observable state of the program and that have no observable effects on such state other than to return a value may lend themselves to optimizations such as common subexpression elimination. Declaring such functions with the const attribute allows GCC to avoid emitting some calls in repeated invocations of the function with the same argument values.

For example, int square (int) attribute ((const)); tells GCC that subsequent calls to function square with the same argument value can be replaced by the result of the first call regardless of the statements in between.

The const attribute prohibits a function from reading objects that affect its return value between successive invocations. However, functions declared with the attribute can safely read objects that do not change their return value, such as non-volatile constants.

The const attribute imposes greater restrictions on a function’s definition than the similar pure attribute. Declaring the same function with both the const and the pure attribute is diagnosed. Because a const function cannot have any observable side effects it does not make sense for it to return void. Declaring such a function is diagnosed.

Note
Note that a function that has pointer arguments and examines the data pointed to must not be declared const if the pointed-to data might change between successive invocations of the function. In general, since a function cannot distinguish data that might change from data that cannot, const functions should never take pointer or, in C++, reference arguments. Likewise, a function that calls a non-const function usually must not be const itself.

Definition at line 102 of file ic_macros.h.

◆ IC_G_ABS

#define IC_G_ABS (   x)    ((x) < 0 ? (-(x)) : (x))

Only use in global scope; absolute value.

Returns
The absolute value of the argument.

Definition at line 30 of file ic_macros.h.

◆ IC_INLINE

#define IC_INLINE   inline __attribute__((always_inline))

Inline the function regardless of optimization level.

Generally, functions are not inlined unless optimization is specified. For functions declared inline, this attribute inlines the function independent of any restrictions that otherwise apply to inlining. Failure to inline such a function is diagnosed as an error. Note that if such a function is called indirectly the compiler may or may not inline it depending on optimization level and a failure to inline an indirect call may or may not be diagnosed.

Definition at line 60 of file ic_macros.h.

◆ IC_PACK

#define IC_PACK   __attribute__((packed))

The packed attribute specifies that a variable or structure field should have the smallest possible alignment—one byte for a variable, and one bit for a field, unless you specify a larger value with the aligned attribute.

Definition at line 68 of file ic_macros.h.

◆ IC_PURE

#define IC_PURE   __attribute__((pure))

Calls to functions that have no observable effects on the state of the program other than to return a value may lend themselves to optimizations such as common subexpression elimination. Declaring such functions with the pure attribute allows GCC to avoid emitting some calls in repeated invocations of the function with the same argument values.

The pure attribute prohibits a function from modifying the state of the program that is observable by means other than inspecting the function’s return value. However, functions declared with the pure attribute can safely read any non-volatile objects, and modify the value of objects in a way that does not affect their return value or the observable state of the program.

For example, int hash (char *) attribute ((pure)); tells GCC that subsequent calls to the function hash with the same string can be replaced by the result of the first call provided the state of the program observable by hash, including the contents of the array itself, does not change in between. Even though hash takes a non-const pointer argument it must not modify the array it points to, or any other object whose value the rest of the program may depend on. However, the caller may safely change the contents of the array between successive calls to the function (doing so disables the optimization). The restriction also applies to member objects referenced by the this pointer in C++ non-static member functions.

Some common examples of pure functions are strlen or memcmp. Interesting non-pure functions are functions with infinite loops or those depending on volatile memory or other system resource, that may change between consecutive calls (such as the standard C feof function in a multithreading environment).

Note
The pure attribute imposes similar but looser restrictions on a function’s definition than the const attribute: pure allows the function to read any non-volatile memory, even if it changes in between successive invocations of the function. Declaring the same function with both the pure and the const attribute is diagnosed. Because a pure function cannot have any observable side effects it does not make sense for such a function to return void. Declaring such a function is diagnosed.

Definition at line 142 of file ic_macros.h.