Thread: Using sizeof( long ) at compile time?

  1. #16
    Kernel hacker
    Join Date
    Jul 2007
    Farncombe, Surrey, England
    Quote Originally Posted by novacain View Post
    Looked at the #error preprocessor command?

    Something like

    #if sizeof(long) != 4
    #error Long incorrect size!
    That was how this started, and the preprocessor can't resolve "sizeof(long)" - it's something the compiler proper needs to do.

    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.

  2. #17
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Maybe I should just do this:
    #if UINT_MAX != 0xFFFFFFFF
    #  error "ints aren't 4 bytes here!"
    Yeah, or, if you know how many bits you want in an unsigned int
    #if UINT_MAX != (1 << 32) - 1
    #error sizeof(unsigned int) != 4
    or, if you have the number of "characters" you want an unsigned int to be,
    #if UINT_MAX != (1 << (4 * CHAR_BIT)) - 1
    #error sizeof(unsigned int) != 4

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell

    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ:

    My website:
    Projects: codeform, xuni, atlantis, nort, etc.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Compiling sample DarkGDK Program
    By Phyxashun in forum Game Programming
    Replies: 6
    Last Post: 01-27-2009, 03:07 AM
  2. Sorting Algorithms with Time
    By silicon in forum C++ Programming
    Replies: 3
    Last Post: 05-03-2005, 11:27 AM
  3. Farmer JoeBot - first project in a LONG time
    By jdinger in forum Game Programming
    Replies: 6
    Last Post: 09-16-2004, 08:57 AM
  4. progarm doesnt compile
    By kashifk in forum Linux Programming
    Replies: 2
    Last Post: 10-25-2003, 05:54 PM
  5. I apologize. Good bye.
    By doubleanti in forum A Brief History of
    Replies: 14
    Last Post: 05-03-2002, 06:51 PM