Explanation on preprocessor directive

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • seforo
    New Member
    • Nov 2006
    • 60

    Explanation on preprocessor directive

    Can someone explain for me what this guy is doing here. N.B homer_uint64 is a defined data type

    #define CLUSTERS_DATAID ((homer_uint64) 'CLUS' << 32 | (homer_uint64)' TERS')
  • Savage
    Recognized Expert Top Contributor
    • Feb 2007
    • 1759

    #2
    [QUOTE]
    Originally posted by seforo
    Can someone explain for me what this guy is doing here. N.B homer_uint64 is a defined data type

    #define CLUSTERS_DATAID ((homer_uint64) 'CLUS' << 32 | (homer_uint64)' TERS')
    This macro would only produce compiler errors when used.
    Are you sure that he didn't use quotes to wrap CLUS and TERS instead of apostrophes?

    In the rest of this post I will assume he had used quotes.So lets break down this macro.

    First part of macro:

    (homer_uint64)" CLUS"<<32 does the following:
    1.It converts a const string "CLUS" to homer_uint64
    2.It shifts its bits for 32 places to the left.

    C=0x43
    L=0x4C
    U=0x55
    S=0x53

    Before shifting:
    0x000000434C555 3.

    After shifting:
    0x434C555300000 000


    Second part of macro ( (homer_uint64)" TERS") also converts const string to homer_uint64 but it doesn't shift it for 32 places.

    So second part is:

    T=0x54
    E=0x45
    R=0x52
    S=0x53

    0x0000000054455 253

    And finally bitwise operator OR(|) merges these two and creates:

    0x434C555300000 000 |
    0x0000000054455 253
    //----------------------------------
    0x434C553544552 53

    [\CODE]

    which the author of this macro uses as symbolic constant for cluster data.

    Comment

    • seforo
      New Member
      • Nov 2006
      • 60

      #3
      He used apostrophes, I just did copy and paste. Thanks for the explanation, it highlighted me a lot.

      Comment

      Working...