Tor  0.4.7.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 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

◆ ARRAY_LENGTH

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

Macro: Yields the number of elements in array x.

Definition at line 222 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 233 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 126 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 246 of file compat_compiler.h.

◆ STMT_NIL

#define STMT_NIL   (void)0

Expands to a syntactically valid empty statement.

Definition at line 166 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 170 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 207 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 218 of file compat_compiler.h.