Compiler attributes and diagnostics utilities

group Compiler attributes

Helper defines for compiler attributes

Defines

a_attr_unused

Mark a value as unsed

Example:

int main(int a_attr_unused argv, char a_attr_unused *argv[])

a_attr_noexport

Mark a symbol in a library as no-export

Prevent external code linking to a non-static function in a library.

a_attr_packed

Pack a structure

Minimize alignment between members in a structure. Useful for saving binary state to files or transport over wire.

a_attr_noreturn

Mark a function as not returning

Inform the compiler that the function will terminate the program.

a_attr_printf(fmtpos, arg1pos)

Mark a function as a function taking printf like arguments

Let the compiler do additional diagnostics on the arguments passed to printf-like functions.

Parameters:
  • fmtpos – 1-index based position of the argument containing the format string

  • arg1pos – 1-index based position of the first formatting argument, The value 0 skips checking arguments. Useful to check only the format string for errors.

group Compiler instrumentation helpers

Various non-attribute macros to more easily access compiler instrumentation helpers for improved diagnostics when compiling.

Defines

a_compiler_is_constant_expr(expr)

Check if the expression can be evaluated at compile time

Warning

Optimization flags may affect the return value

Parameters:
  • expr – The expression to test

Returns:

1 if it can be evaluated, 0 otherwise

a_compiler_is_same_type(type1, type2)

Check if two types are equivalent

Parameters:
  • type1 – First type in the comparison

  • type2 – Second type in the comparison

Returns:

1 if types are equivalent, 0 otherwise

a_compiler_choose_expr(cond, expr_true, expr_false)

Choose expression in compile time

Chooses between expr_true and expr_false based on compile time evaluation of cond . Only the chosen expression is evaluated.

Parameters:
  • cond – Condition to evaluate

  • expr_true – Expression to evaluate if cond evaluates to True

  • expr_false – Expression to evaluate if cond evaluates to False

Returns:

Whatever the chosen expression returns