[LCP]struct & union
Paul Gearon
pag at PISoftware.com
Mon Feb 4 18:05:18 UTC 2002
On Mon, 4 Feb 2002, Greg Black wrote:
> Paul Gearon wrote:
>
> | The size of a float is part of the standard.
>
> Only in part.
True, but I pointed out that 4 bytes is considered "adequate" and was not
mandatory.
> | The C99 standard says that it extends C89, and the C89 Rational document
> | says:
>
> Note that the "Rationale" is not itself part of the Standard and
> nothing in it is binding.
Yeah, OK, but I couldn't find the standard doc at short notice. :-)
> | Someone here may have a more accurate picture of what size an int is in a
> | given circumstance. These days I just accept that it's 32 bits since
> | everyone seems to have standardized on that size.
>
> Not at all. People running 16-bit or smaller CPUs will almost
> certainly be using 16-bit "int". People with big registers may
> well use 64-bit or 128-bit sizes for "int". Of course, as so
> many people discovered when 64-bit CPUs started to be used more
> widely, lots of software is written by people who just don't
> understand C's size rules and who write software that breaks in
> the face of "unexpected" sizes of "int", "long", etc.
OK, this is where I should have been clearer. On 16 bit processors you
will certainly find that sizeof(int)==2, but I once used a compiler for an
8 bit processor where sizeof(int)==2. For PC/Workstation applications
things are also a little strange because there seems to be a blind
adherence to 32 bits.
For instance, M$ changed the size of an int to 32 bits without a CPU
change. Also, I kept expecting to find 64 bit ints on 64 bit
architectures, but I keep finding 32 bit ints instead, with names like
"long long" being used for 64 bits. It seems to me that many (not all)
compiler writers have built a de facto standard on the 32 bit int without
consulting if anyone really wanted it. I guess it's a mistake to assume
that it will *always* be 32 bit, but on a desktop machine I don't think
you'll find anything else.
So yeah, if I need to use bitmasks I'll use sizeof and the shift
operators, but if someone asks how large an int is I'll say that it's
normally 4 bytes. :-)
Regards,
Paul Gearon
Software Engineer Telephone: +61 7 3876 2188
Plugged In Software Fax: +61 7 3876 4899
http://www.PIsoftware.com PGP Key available via finger
Catapultam habeo. Nisi pecuniam omnem mihi dabis, ad caput tuum saxum
immane mittam.
(Translation from latin: "I have a catapult. Give me all the money,
or I will fling an enormous rock at your head.")
More information about the linuxCprogramming
mailing list