sizeof(int) on x64 system?

Discussion in 'Windows 64bit' started by David, Aug 9, 2006.

  1. David

    David Guest

    I've built some code under Visual Studio C++ (2005) and sizeof(int) is
    4 bytes whether the code is built for 32 or 64 bit platforms. (I'm
    running on a 64 bit machine.)

    I was of the impression that the Ansi spec defines 'int' to be the same
    as the native word size of the machine. Am I wrong or is there a
    compile flag or manifest that would get sizeof(int) to be 8?

    Thanks.

    - David
     
    David, Aug 9, 2006
    #1
    1. Advertisements

  2. I think you are right. I can't tell you what it is, but most likely a
    pre-processor directive.


    Tony. . .
     
    Tony Sperling, Aug 9, 2006
    #2
    1. Advertisements

  3. David

    Bo Persson Guest

    For some definition of 'native'. :)

    For x64, a 32 bit int *is* the native size, as it produces the
    smallest code size. To use 64 bit operands, the machine code must
    include a size override prefix.
    No, there is not.

    On some systems, Linux in particular, sizeof(long) might be 8. With MS
    C++, sizeof(long)==sizeof(int)==8.


    Bo Persson
     
    Bo Persson, Aug 9, 2006
    #3
  4. David

    Bo Persson Guest

    ^^^^

    Shit! :)

    It looks kinda like an 8, but is really a 4 (four). Honest!


    Bo Persson
     
    Bo Persson, Aug 9, 2006
    #4
  5. The only thing the C and C++ standards define as far as type sizes is
    concerned is:

    sizeof char <= sizeof short <= sizeof int <= sizeof long

    Win64 defines int and long to be 32-bit. Presumably for compatibility
    reasons as much as anything else. Be aware that size_t is 64-bit though.
    (This is currently causing me a few headaches.)


    (Another gotcha to watch out for is NULL still being defined as 0 instead of
    0LL. Which is a real problem when you try to pass a NULL pointer to a
    varargs function. The caller pushes a 32-bit integer 0, while the callee
    tries to retrieve a 64-bit pointer 0. Oh the fun I had with that one...)
     
    James Robertson, Aug 10, 2006
    #5
  6. (Another gotcha to watch out for is NULL still being defined as 0 instead
    Stop it, you're creeping me out...
     
    Homer J. Simpson, Aug 10, 2006
    #6
  7. David

    tha_specializt

    Joined:
    Dec 20, 2007
    Messages:
    1
    Likes Received:
    0
    Wow, it appears you dont know what you're talking about ....

    msdn.microsoft.com/en-us/library/aa383751%28v=VS.85%29.aspx

    Both sizeof(int) and sizeof(long) == 4. Learn to use Google before you post things
     
    tha_specializt, Mar 18, 2010
    #7
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.