Thread: what does "U" mean in a macro?

  1. #1
    Registered User
    Join Date
    Apr 2008
    Posts
    9

    what does "U" mean in a macro?

    Hi,
    Could some body tell me what exactly "U" means in a macro like,
    Code:
    #define INVALID  -1U
    
    //Can I write in this way in C and also is it correct if I write some condition as follows in my code.
    
    uint32 x;
    ----
    ---
    if( x != INVALID )
    {
    -------
    }
    My intention is to check if X not equal to -1.

    Thanks,
    tummala

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    It's not to do with macro, but with "numbers", U means unsigned, so in this instance it says "A value of -1 that is unsigned". That helps when you want to assign an unsigned variable with the special value that is "all ones".

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    Registered User
    Join Date
    Apr 2008
    Posts
    9
    ok in that case will it serve the purpose in the code.
    I was getting "integer conversion resulted in a change of sign" warning, if I don't put U.
    But now I am not sure if placing U beside -1 makes it a 32 bit unsigned value??

  4. #4
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    The U makes it an unsigned value, yes. It doesn't say anything about the number of bits of the value. Hopefully uint32 is correctly defined, and thus will be a 32-bit value.

    Basically, the U says "Look, this may look like a signed value, but I'd like you to treat it as it wasn't" to the compiler.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  5. #5
    Registered User
    Join Date
    Apr 2008
    Posts
    9
    ok,that was helpful.
    Thanks!!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem building Quake source
    By Silvercord in forum Game Programming
    Replies: 16
    Last Post: 07-11-2010, 09:13 AM
  2. Errors including <windows.h>
    By jw232 in forum Windows Programming
    Replies: 4
    Last Post: 07-29-2008, 01:29 PM
  3. Quantum Random Bit Generator
    By shawnt in forum C++ Programming
    Replies: 62
    Last Post: 06-18-2008, 10:17 AM
  4. need help with multi line macro usage
    By Cdigitproc1 in forum C Programming
    Replies: 9
    Last Post: 04-29-2005, 09:50 AM
  5. Macro Program
    By daspope in forum Windows Programming
    Replies: 5
    Last Post: 04-25-2004, 04:02 AM