Results 1 to 3 of 3

Thread: [RESOLVED] sizeof

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2002
    Posts
    258

    Resolved [RESOLVED] sizeof

    Could someone tell me why the following code doesn't work?

    #if sizeof(int) > 1
    //do something
    #endif

    When it's compiled it doesn't like the use of the sizeof operator and throws out an error... forgot what the error was, I did this at work.

    I'm sure it must be something to do with the precedense of compilation but I can't find anything on the web that explains the failure.

    I'm using a keil c166 compiler.

    Any help, much appreciated.

  2. #2
    New Member cilu's Avatar
    Join Date
    Jan 2006
    Location
    Timisoara, Romania
    Posts
    7

    Re: sizeof

    You can only use integer constant expression there. sizeof(int) is determined at compile time, but the macros are parsed at pre-compile time. So it can't work.
    CodeGuru Moderator & Article Reviewer

    Differences of habit and language are nothing at all if our aims are identical and our hearts are open. - J.K. Rowling, HP and the Goblet of Fire

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2002
    Posts
    258

    Re: sizeof

    Sounds reasonable. Thought it must be something to do with the order of pre-processor/compiler. I'll just use a CompileAssert then.

    Thanks.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width