Sizeof(X) on different architectures

From: Martin Roos (martin_at_none.ee)
Date: 09/27/04


Date: Mon, 27 Sep 2004 09:54:38 +0300


hy ppl, i'm trying to create some multiplatformed software here and i'm very curious about the sizes of common variables on different machines.

if you are running something different than a 32-bit x86 box under your desk, please check what this program outputs.

//-- program starts --

#include <stdio.h>

#define showsize(x,y) printf("Size of %s %d \n",x,sizeof(y));

typedef struct db_s{
        int offset;
        int length;
        char* data;
} db;

int main() {
        showsize("char",char);
        showsize("int",int);
        showsize("long",long);
        showsize("char*",char*);
        showsize("int*",int*);
        showsize("long*",long*);
        showsize("void*",void*);
        showsize("db",db);
        showsize("db*",db*);
        return 0;
}

//-- program ends --

on an 32bit x86 it reports like this :

Size of char 1
Size of int 4
Size of long 4
Size of char* 4
Size of int* 4
Size of long* 4
Size of void* 4
Size of db 12
Size of db* 4

.....

are there any 64bit sun users out there ? 64bit x86 machine owners and mac users ?

if you can please report in :)



Relevant Pages

  • Re: Is there any GENRIC MACROS in c for INTEGERS,CHARACTERS ?
    ... > The descriptions of the ctype functions all take int values. ... > char is converted to int in this case and that if char is signed and ... kin just take the argument value, subtract EOF, and use the ... machines disagree on just what should happen ...
    (comp.lang.c)
  • Re: Question about void pointers
    ... int main ... char t; ... pointers are printed as number here, but they probably don't behave like ... I just hope word-addressed machines don't make a big comeback. ...
    (comp.lang.c)
  • Re: Sizeof(X) on different architectures
    ... > very curious about the sizes of common variables on different machines. ... Size of char* 8 ... Size of int* 8 ...
    (comp.lang.c)
  • Re: Good Tutorials
    ... but a short int is exactly two bytes, ... On many machines that's true; though the standard imposes no such ... There are other machines where char is 8 bits, ... because non-military scientific computer programming doesn't tend to ...
    (comp.lang.c)
  • Re: P 155 k&r section 7.3
    ... On many machines 'int' and 'char *' are the same size, ... representation, and are, basically, interchangeable. ...
    (comp.lang.c)