[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: amd64: why is sizeof(int) =4? why not =8?



Mitchell Laks wrote:
Hi,

I wanted to find out more about amd64, so I installed the debian distro (etch/sid) on my amd64 dual core system. I wanted to see if it is really 64 bit. So naively i compiled the following example program I found on the internet:

The size of an int has nothing to do with the machine, and
everything to do with the compiler. If you like, I'll send
you a copy of a C compiler which will run on your machine,
and the program will tell you that sizeof(int) is 2.


#include <stdio.h>
#include <stdlib.h>
#include <string.h>

typedef struct employee_st {
    char name[40];
    int id;
} Employee;

int main()
{
    int myInt;
    Employee john;

    printf("Size of int is %d\n",sizeof(myInt));

This program has defects. The type of the results of
the sizeof operator is an unsigned integer of unspecified
size. The only portable way to do this is...

    printf("Size of int is %lu\n",(unsigned long)sizeof(int));

[snip]

and the output is  no different from on my 32 bit system.

As expected. Once the compiler is run, and the program
created, the instructions are whatever they are. There is
no run time size detection and re-writing of the program.
C is not an interpreted language.

So how do I see the 64 bittness of the operating system if not this way with gcc? I would think tha size of int would be 8?
uname -a
Linux Rashi 2.6.16.1-meshulum-2006-4-5 #1 SMP Wed Apr 5 13:34:46 EDT 2006 x86_64 GNU/Linux.

You need to get a 64 bit compiler. The programs it creates will
not run on a 32 bit machine, and likely not with a 32 bit OS
even on your 64 bit machine.

Mike
--
p="p=%c%s%c;main(){printf(p,34,p,34);}";main(){printf(p,34,p,34);}
This message made from 100% recycled bits.
You have found the bank of Larn.
I can explain it for you, but I can't understand it for you.
I speak only for myself, and I am unanimous in that!



Reply to: