Re: [GD-General] meaning of sizeof(int) on all plateform
Brought to you by:
vexxed72
From: Evan R. <ev...@en...> - 2003-06-26 22:25:11
|
From: Evan Robinson <ero...@en...> Date: Thu Jun 26, 2003 2:36:27 PM US/Pacific To: gam...@li... Subject: Re: [GD-General] meaning of sizeof(int) on all plateform On Thursday, June 26, 2003, at 01:12 PM, Lagarde S=E9bastien wrote: > no confusion here, > Following suestion here are purelly curiosity: > =A0 > i precise the question: > =A0 > if you have a 32 bit architecture (pentium) > if you want make fast arithmetic operation, you > must work with type which have a size of 32bits. > These type have the same size of a register and the > arithmetic operation can be optimize... > typically, this is type "int" > =A0 > on a 64 bit architecture (itanium) > register are 64 bit and int are 64bit too > =A0 > so if you have a program which perform the following code: > =A0 > // imaginary define > // the goal of this define is to have s32 on 32bits > #ifdef __32Bit__ > typedef int s32 > #else // __64bit__ > typedef short u32=A0 // just for exemple > #endif > =A0 > void add(s32 a1, s32 a2) > { > =A0=A0=A0 return a1 + a2; > } > =A0 > the performance can be poor on a 64bit architecture because we are not > in the native size of the register > =A0 > if we have this code > =A0 > void add(int a1,=A0int a2) > { > =A0=A0=A0 return a1 + a2; > } > =A0 > no problem, cause "int" is native to the architecture Not necessarily. "int" is a logical construct *of the compiler*, not=20 *of the platform*. You *hope* that your compiler vendor has made int=20 the most efficient size for general purpose integer math. > it is my imagination, I'am in the wrong way ? > =A0 > another question, is sizeof(int) =3D=3D sizeof(void*) ? > sizeof(void*) must be : size of memory bus address > so sizeof(int).... Once again, not necessarily. "void *" is a logical construct "of the=20 compiler*. You would expect a void * to be as many bits as necessary=20 to express the entire memory footprint of the computer architecture,=20 but there is no reason why it couldn't be either larger or smaller,=20 depending upon the compiler vendor. A straightforward (if evil)=20 example would be the segmented 8088 architecture, where the base memory=20= footprint was 1024K, but the RAM footprint was generally 640K, and full=20= pointers were 32 bits (16 bit segment, 16 bit offset). A 20-bit=20 pointer would have sufficed for the base memory footprint, but could=20 not have properly expressed all segment:offset pairs If you are trying to make sure that your code will run equally=20 efficiently on *all platforms* and *all compilers*, you are (probably=20 wasting your time) probably best off relying on "int" and "void *" and=20= not worrying about how they match to the platform until you have a=20 specific platform and compiler combination in mind. > -------------------------- > Lagarde S=E9bsatien > Neko entertainment > Junior programmer > > ----- Original Message ----- > From: Mick West > To: gam...@li... > Sent: Thursday, June 26, 2003 8:48 PM > Subject: RE: [GD-General] meaning of sizeof(int) on all plateform > > 128 bits would give you 16 bytes, not 32. > =A0 > On the PS2 an int is generally 32 BITS,=A0 (4 bytes), which is maybe=20= > where the confusion arose. > =A0 > Mick > > > -----Original Message----- > From: gam...@li...=20 > [mailto:gam...@li...] On Behalf Of=20= > Gareth Lewin > Sent: Thursday, June 26, 2003 11:42 AM > To: gam...@li... > Subject: RE: [GD-General] meaning of sizeof(int) on all plateform > > sizeof(int) =3D size of integer value. As defined by the compiler=20 > vendor. There is no "Correct" way to set the size of int. > > -----Original Message----- > From: Lagarde S=E9bastien [mailto:Lag...@wa...] > Sent: 26 June 2003 19:36 > To: gam...@li... > Subject: [GD-General] meaning of sizeof(int) on all plateform > > Hello all, > I have some problem to define what represent sizeof(int). > =A0 > IMO sizeof(int) =3D=3D memory bus address width > =A0 > but on platforme like PS2, you have a bus of 128 and sizeof(int) =3D=3D = 32. > =A0 > i have seen elsewherre that sizeof(int) =3D=3D size of a register. > =A0 > Is someone have some information on this point ? > thanks > ------------------------------- > Lagarde S=E9bastien > Neko entertainment > Junior programmer > =A0 > > -- Engines of Mischief Consulting =20 <http://www.enginesofmischief.com> Mischievous Ramblings =20 <http://www.enginesofmischief.com/blogs/ramblings> The Engine of Mischief =20 <http://www.enginesofmischief.com/engine> Mischief's Travelblog =20 <http://www.enginesofmischief.com/blogs/travelblog> I pledge allegiance to the flag of the multinational corporations and to the profit for which they stand, one interlocking directorate under no government, indivisible, with monopoly and cheap labor for=20 all. -- U. Utah Phillips, "Stupid's Pledge" |