Export (0) Print
Expand All

C_ASSERT macro

Checks assertions at compile time.

Syntax


void C_ASSERT(
   expr
);

Parameters

expr

An expression that can be determined at compile time.

Return value

If the assertion succeeds, the expression evaluates to typedef char __C_ASSERT__[1];, which the compiler will accept.

If the assertion fails, the expression evaluates to typedef char __C_ASSERT__[-1];, which results in a compilation error because negative subscripts are not valid.

Remarks

The C_ASSERT macro is defined as follows.


#define C_ASSERT(e) typedef char __C_ASSERT__[(e)?1:-1]

The following examples demonstrate common types of compile-time assertions.


C_ASSERT (BUFFER_CCH_SIZE <= MAX_PATH);

C_ASSERT (ARRAYSIZE(array1) == ARRAYSIZE(array2));

C_ASSERT (FIELD_OFFSET(STRUCT_DEF, MemberName) == 0x1d4);

C_ASSERT (sizeof(BOOLEAN) == sizeof(UCHAR));

Requirements

Header

WinNT.h (include Windows.h)

 

 

Community Additions

ADD
Show:
© 2014 Microsoft