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. Advertising

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


    Tony. . .


    "David" <> wrote in message
    news:...
    > 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
    >
    Tony Sperling, Aug 9, 2006
    #2
    1. Advertising

  3. David

    Bo Persson Guest

    "David" <> skrev i meddelandet
    news:...
    > 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.


    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.

    > Am I wrong or is there a
    > compile flag or manifest that would get sizeof(int) to be 8?


    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

    "Bo Persson" <> skrev i meddelandet
    news:OyrjQn%...
    >
    > "David" <> skrev i meddelandet
    > news:...
    >> 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.

    >
    > 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.
    >
    >> Am I wrong or is there a
    >> compile flag or manifest that would get sizeof(int) to be 8?

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

    ^^^^

    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...)



    "David" <> wrote in message
    news:...
    > 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
    >
    James Robertson, Aug 10, 2006
    #5
  6. > (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...)


    Stop it, you're creeping me out...
    Homer J. Simpson, Aug 10, 2006
    #6
  7. David

    tha_specializt

    Joined:
    Dec 20, 2007
    Messages:
    1
    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. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. shope
    Replies:
    1
    Views:
    5,097
    Hapee
    Jul 17, 2003
  2. Mike Gallagher
    Replies:
    0
    Views:
    442
    Mike Gallagher
    Jul 19, 2003
  3. AJ
    Replies:
    2
    Views:
    3,460
    Johnny Bravo
    Oct 31, 2003
  4. Jeff
    Replies:
    2
    Views:
    658
  5. jason b

    syslog logging on dhcp int

    jason b, Feb 1, 2004, in forum: Cisco
    Replies:
    1
    Views:
    477
    Martin Gallagher
    Feb 1, 2004
Loading...

Share This Page