#ifndef EIGHT_BIT
#define THIRTYTWO_BIT // default 32 bit
#endif
#ifdef THIRTYTWO_BIT
#define WORD unsigned long
#define WORDLENGTH 4
#if defined(WIN32) && !defined(__GNUC__)
#define WORD64 unsigned __int64
#else
#define WORD64 unsigned long long
#endif
// THIRTYTWO_BIT
#endif
#ifdef EIGHT_BIT
#define WORD unsigned short
#define WORDLENGTH 4
// EIGHT_BIT
#endif
#ifndef EIGHT_BIT #define THIRTYTWO_BIT // default 32 bit #endif #ifdef THIRTYTWO_BIT #define WORD unsigned
Share
The first thing to note about this code is that none of it will actually be compiled into C. Every line that isn’t whitespace or a comment starts with a pound sign (
#), meaning they are preprocessor directives. A preprocessor directive alters the code before it even makes it to the compiler. For more information of preprocessor directives, see this article.Now that we know that much, let’s look through the code:
If the macro
EIGHT_BITis not defined, define another macro calledTHIRTYTWO_BIT. This is most likely referring to the number of bits in a word on a processor. This code intends to be cross-platform, meaning that it can run on a number of processors. The snippet you posted pertains to managing different word widths.If the macro
THIRTYTWO_BITis defined, then define aWORDto be anunsigned long, which has aWORDLENGTHof 4 (presumably bytes). Note that this statement isn’t necessarily true, as the C standard only guarantees that alongwill be as least as long as anint.If this is a 32-bit Windows platform and the GNU C compiler is not available, then use the Microsoft-specific datatype for 64-bit words (
unsigned __int64). Otherwise, use the GNU C datatype (unsigned long long).Every
#ifand#ifdefdirective must be matched by a corresponding#endifto delineate where the conditional section ends. This line ends the#ifdef THIRTYTWO_BITdeclaration made previously.If the target processor has a word width of 8 bits, then define a
WORDto be anunsigned short, and define theWORDLENGTHto be 4 (again, presumably in bytes).