c++ - Can anyone explain me this code -


#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 

the first thing note code none of compiled c. every line isn't whitespace or comment starts pound sign (#), meaning preprocessor directives. preprocessor directive alters code before makes compiler. more information of preprocessor directives, see this article.

now know much, let's through code:


#ifndef eight_bit #define thirtytwo_bit // default 32 bit #endif 

if macro eight_bit not defined, define macro called thirtytwo_bit. referring number of bits in word on processor. code intends cross-platform, meaning can run on number of processors. snippet posted pertains managing different word widths.


#ifdef thirtytwo_bit #define word unsigned long #define wordlength 4 

if macro thirtytwo_bit defined, define word unsigned long, has wordlength of 4 (presumably bytes). note statement isn't true, c standard guarantees long least long int.


#if defined(win32) && !defined(__gnuc__) #define word64  unsigned __int64 #else #define word64  unsigned long long #endif 

if 32-bit windows platform , gnu c compiler not available, use microsoft-specific datatype 64-bit words (unsigned __int64). otherwise, use gnu c datatype (unsigned long long).


// thirtytwo_bit #endif 

every #if , #ifdef directive must matched corresponding #endif delineate conditional section ends. line ends #ifdef thirtytwo_bit declaration made previously.


#ifdef eight_bit  #define word unsigned short #define wordlength 4  // eight_bit #endif 

if target processor has word width of 8 bits, define word unsigned short, , define wordlength 4 (again, presumably in bytes).


Comments

Popular posts from this blog

c++ - Is it possible to compile a VST on linux? -

java - Output of Eclipse is rubbish -

jquery - Confused with JSON data and normal data in Django ajax request -