Tor 0.4.9.0-alpha-dev
Macros
compat_compiler.h File Reference

Utility macros to handle different features and behavior in different compilers. More...

#include "orconfig.h"
#include <inttypes.h>

Go to the source code of this file.

Macros

#define PRINTF_FORMAT_ATTR   printf
 
#define SCANF_FORMAT_ATTR   scanf
 
#define CHECK_PRINTF(formatIdx, firstArg)
 
#define CHECK_SCANF(formatIdx, firstArg)
 
#define FALLTHROUGH
 
#define GCC_VERSION   0
 
#define DISABLE_GCC_WARNING(warning)
 
#define ENABLE_GCC_WARNING(warning)
 
#define __func__   "???"
 
#define ENUM_BF(t)   t
 
#define ATTR_NORETURN
 
#define ATTR_CONST
 
#define ATTR_MALLOC
 
#define ATTR_NORETURN
 
#define ATTR_UNUSED
 
#define ATTR_WUR
 
#define PREDICT_LIKELY(exp)   (exp)
 
#define PREDICT_UNLIKELY(exp)   (exp)
 
#define STMT_NIL   (void)0
 
#define STMT_VOID(a)   while (0) { (void)(a); }
 
#define STMT_BEGIN   do {
 
#define STMT_END   } while (0)
 
#define OP_LT   <
 
#define OP_GT   >
 
#define OP_GE   >=
 
#define OP_LE   <=
 
#define OP_EQ   ==
 
#define OP_NE   !=
 
#define STRUCT_VAR_P(st, off)   ((void*) ( ((char*)(st)) + (off) ) )
 
#define SUBTYPE_P(p, subtype, basemember)    ((void*) ( ((char*)(p)) - offsetof(subtype, basemember) ))
 
#define ARRAY_LENGTH(x)   ((sizeof(x)) / sizeof(x[0]))
 
#define EAT_SEMICOLON    struct dummy_semicolon_eater__
 
#define POSSIBLE(expr)   (expr)
 

Detailed Description

Utility macros to handle different features and behavior in different compilers.

Definition in file compat_compiler.h.

Macro Definition Documentation

◆ __func__

#define __func__   "???"

Definition at line 137 of file compat_compiler.h.

◆ ARRAY_LENGTH

#define ARRAY_LENGTH (   x)    ((sizeof(x)) / sizeof(x[0]))

Macro: Yields the number of elements in array x.

Definition at line 241 of file compat_compiler.h.

◆ ATTR_CONST

#define ATTR_CONST

Definition at line 179 of file compat_compiler.h.

◆ ATTR_MALLOC

#define ATTR_MALLOC

Definition at line 180 of file compat_compiler.h.

◆ ATTR_NORETURN [1/2]

#define ATTR_NORETURN

Definition at line 181 of file compat_compiler.h.

◆ ATTR_NORETURN [2/2]

#define ATTR_NORETURN

Definition at line 181 of file compat_compiler.h.

◆ ATTR_UNUSED

#define ATTR_UNUSED

Definition at line 182 of file compat_compiler.h.

◆ ATTR_WUR

#define ATTR_WUR

Definition at line 183 of file compat_compiler.h.

◆ CHECK_PRINTF

#define CHECK_PRINTF (   formatIdx,
  firstArg 
)

Definition at line 67 of file compat_compiler.h.

◆ CHECK_SCANF

#define CHECK_SCANF (   formatIdx,
  firstArg 
)

Definition at line 73 of file compat_compiler.h.

◆ DISABLE_GCC_WARNING

#define DISABLE_GCC_WARNING (   warning)

Definition at line 114 of file compat_compiler.h.

◆ EAT_SEMICOLON

#define EAT_SEMICOLON    struct dummy_semicolon_eater__

"Eat" a semicolon that somebody puts at the end of a top-level macro.

Frequently, we want to declare a macro that people will use at file scope, and we want to allow people to put a semicolon after the macro.

This declaration of a struct can be repeated any number of times, and takes a trailing semicolon afterwards.

Definition at line 252 of file compat_compiler.h.

◆ ENABLE_GCC_WARNING

#define ENABLE_GCC_WARNING (   warning)

Definition at line 115 of file compat_compiler.h.

◆ ENUM_BF

#define ENUM_BF (   t)    t

Wrapper for having a bitfield of an enumerated type. Where possible, we just use the enumerated type (so the compiler can help us and notice problems), but if enumerated types are unsigned, we must use unsigned, so that the loss of precision doesn't make large values negative.

Definition at line 149 of file compat_compiler.h.

◆ FALLTHROUGH

#define FALLTHROUGH

Definition at line 79 of file compat_compiler.h.

◆ GCC_VERSION

#define GCC_VERSION   0

Definition at line 86 of file compat_compiler.h.

◆ OP_EQ

#define OP_EQ   ==

Definition at line 214 of file compat_compiler.h.

◆ OP_GE

#define OP_GE   >=

Definition at line 212 of file compat_compiler.h.

◆ OP_GT

#define OP_GT   >

Definition at line 211 of file compat_compiler.h.

◆ OP_LE

#define OP_LE   <=

Definition at line 213 of file compat_compiler.h.

◆ OP_LT

#define OP_LT   <

Definition at line 210 of file compat_compiler.h.

◆ OP_NE

#define OP_NE   !=

Definition at line 215 of file compat_compiler.h.

◆ POSSIBLE

#define POSSIBLE (   expr)    (expr)

Tell our static analysis tool to believe that (clang's scan-build or coverity scan) that an expression might be true. We use this to suppress dead-code warnings.

Definition at line 265 of file compat_compiler.h.

◆ PREDICT_LIKELY

#define PREDICT_LIKELY (   exp)    (exp)

Definition at line 184 of file compat_compiler.h.

◆ PREDICT_UNLIKELY

#define PREDICT_UNLIKELY (   exp)    (exp)

Definition at line 185 of file compat_compiler.h.

◆ PRINTF_FORMAT_ATTR

#define PRINTF_FORMAT_ATTR   printf

Definition at line 54 of file compat_compiler.h.

◆ SCANF_FORMAT_ATTR

#define SCANF_FORMAT_ATTR   scanf

Definition at line 59 of file compat_compiler.h.

◆ STMT_BEGIN

#define STMT_BEGIN   do {

Definition at line 204 of file compat_compiler.h.

◆ STMT_END

#define STMT_END   } while (0)

Definition at line 205 of file compat_compiler.h.

◆ STMT_NIL

#define STMT_NIL   (void)0

Expands to a syntactically valid empty statement.

Definition at line 189 of file compat_compiler.h.

◆ STMT_VOID

#define STMT_VOID (   a)    while (0) { (void)(a); }

Expands to a syntactically valid empty statement, explicitly (void)ing its argument.

Definition at line 193 of file compat_compiler.h.

◆ STRUCT_VAR_P

#define STRUCT_VAR_P (   st,
  off 
)    ((void*) ( ((char*)(st)) + (off) ) )

Macro: yield a pointer to the field at position off within the structure st. Example:

  struct a_t { int foo; int bar; } x;
  ptrdiff_t bar_offset = offsetof(struct a_t, bar);
  int *bar_p = STRUCT_VAR_P(&x, bar_offset);
  *bar_p = 3;

Definition at line 226 of file compat_compiler.h.

◆ SUBTYPE_P

#define SUBTYPE_P (   p,
  subtype,
  basemember 
)     ((void*) ( ((char*)(p)) - offsetof(subtype, basemember) ))

Macro: yield a pointer to an enclosing structure given a pointer to a substructure at offset off. Example:

  struct base_t { ... };
  struct subtype_t { int x; struct base_t b; } x;
  struct base_t *bp = &x.base;
  struct *sp = SUBTYPE_P(bp, struct subtype_t, b);

Definition at line 237 of file compat_compiler.h.