Thread: x86 64 C data type sizes

  1. #1
    Dump Truck Internet valis's Avatar
    Join Date
    Jul 2005
    Posts
    357

    x86 64 C data type sizes

    I am writing some code which is very dependant on the size of the data worked with. I have it written so that size shouldn't matter as long as the return data type is twice as large as one of the parameters.
    I was searching google and found a piece on a site that stated int on x86 64 is still only 4 bytes, can anyone verify this?
    Also if the above is not true (int is 8), on an x86 64 is a short 32 bits?

    Thanks

  2. #2
    ... kermit's Avatar
    Join Date
    Jan 2003
    Posts
    1,534
    Various sizes on my machine (AMD Athlon64 chip)

    Code:
    Signed    : Size                    Min                    Max
    --------------------------------------------------------------
    char      :    1                   -128                    127
    short     :    2                 -32768                  32767
    int       :    4            -2147483648             2147483647
    long      :    8   -9223372036854775808    9223372036854775807
    long long :    8   -9223372036854775808    9223372036854775807
    
    Unsigned  : Size                    Min                    Max
    --------------------------------------------------------------
    char      :    1                      0                    255
    short     :    2                      0                  65535
    int       :    4                      0             4294967295
    long      :    8                      0   18446744073709551615
    long long :    8                      0   18446744073709551615
    
    Miscellaneous sizes:
    --------------------------------------------------------------
    Single precision float:                                      4
    Double precision float:                                      8
    size_t:                                                      8
    ssize_t:                                                     8
    Pointers are 8 as well...

    And here is the code I used to generate that with:

    Code:
    #include <stdio.h>
    #include <limits.h>
    #include <unistd.h>             /* For the ssize_t header */
    
    int main(void)
    {
        printf("\n\nSigned    : Size %22s %22s\n", "Min", "Max");
        printf
            ("--------------------------------------------------------------\n");
        printf("char      : %4d %22d %22d\n", (int) sizeof(char), CHAR_MIN,
               CHAR_MAX);
        printf("short     : %4d %22d %22d\n", (int) sizeof(short), SHRT_MIN,
               SHRT_MAX);
        printf("int       : %4d %22d %22d\n", (int) sizeof(int), INT_MIN,
               INT_MAX);
        printf("long      : %4d %22ld %22ld\n", (int) sizeof(long), LONG_MIN,
               LONG_MAX);
        printf("long long : %4d %22lld %22lld\n\n", (int) sizeof(long long),
               LLONG_MIN, LLONG_MAX);
    
        printf("Unsigned  : Size %22s %22s\n", "Min", "Max");
        printf
            ("--------------------------------------------------------------\n");
        printf("char      : %4d %22d %22u\n", (int) sizeof(unsigned char), 0,
               UCHAR_MAX);
        printf("short     : %4d %22d %22u\n", (int) sizeof(unsigned short), 0,
               USHRT_MAX);
        printf("int       : %4d %22d %22u\n", (int) sizeof(unsigned int), 0,
               UINT_MAX);
        printf("long      : %4d %22d %22lu\n", (int) sizeof(unsigned long), 0,
               ULONG_MAX);
        printf("long long : %4d %22d %22llu\n\n",
               (int) sizeof(unsigned long long), 0, ULLONG_MAX);
    
        printf("Miscellaneous sizes:\n");
        printf
            ("--------------------------------------------------------------\n");
    
        printf("Single precision float: %38d\n", (int) sizeof(float));
        printf("Double precision float: %38d\n", (int) sizeof(double));
        printf("size_t: %54d\n", (int) sizeof(size_t));
        printf("ssize_t: %53d\n", (int) sizeof(ssize_t));
    
        return 0;
    }
    Last edited by kermit; 07-24-2006 at 06:45 PM.

  3. #3
    Dump Truck Internet valis's Avatar
    Join Date
    Jul 2005
    Posts
    357
    Well damn, int is still only 4, much thanks.

  4. #4
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,005
    Some types may also depend on the OS, not just the platform.
    https://cboard.cprogramming.com/showthread.php?p=468408
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  5. #5
    Dump Truck Internet valis's Avatar
    Join Date
    Jul 2005
    Posts
    357
    Thanks, that's very good to know, thankfully this app isn't meant for windows.

    With cl do you have to use __int64 for a 64 bit data type, or will long long/int do it as well?

  6. #6
    ... kermit's Avatar
    Join Date
    Jan 2003
    Posts
    1,534
    Quote Originally Posted by Dave_Sinkula
    Some types may also depend on the OS, not just the platform.
    https://cboard.cprogramming.com/showthread.php?p=468408
    That is some good reading - thanks for the link Dave.

  7. #7
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    Starting with 7.1, MSC++ supports the long long datatype.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  2. Can you check what is wrong with this code
    By Ron in forum C++ Programming
    Replies: 4
    Last Post: 08-01-2008, 10:59 PM
  3. Using VC Toolkit 2003
    By Noobwaker in forum Windows Programming
    Replies: 8
    Last Post: 03-13-2006, 07:33 AM
  4. Problem with Visual C++ Object-Oriented Programming Book.
    By GameGenie in forum C++ Programming
    Replies: 9
    Last Post: 08-29-2005, 11:21 PM
  5. C diamonds and perls :°)
    By Carlos in forum A Brief History of Cprogramming.com
    Replies: 7
    Last Post: 05-16-2003, 10:19 PM