int32 et al.

Benson I. Margulies benson at odi.com
Wed Jan 23 04:59:00 AEST 1991


In article <1991Jan22.023844.29849 at dirtydog.ima.isc.com> karl at ima.isc.com (Karl Heuer) writes:
>In article <1991Jan21.135216.23447 at odi.com> benson at odi.com (Benson I. Margulies) writes:
>>>>If we used int for a 32 byte int, we are nailed on the PCs.  If we use
>>>>long, C++ compilers tend to moan piteously about [type clash]
>>
>>The system include files contain
>>	extern int blahblah (int, char *);
>>I don't control that declaration. If I call blahblah with a long,
>>the compiler bleats a warning.
>
>How does int32 help, then?  You said you define int32 as long on some machines
>(PCs), so passing an int32 to this function is just wrong.  Looks to me as
>though you need to cast% it to int, regardless of whether you're using int32
>or long.
>
>>for 
>>	extern int quux (int *);
>>if I pass a long * I get an error, not just a warning.
>>So I can't just use long all the time unless I type in all my
>>own system function prototypes.
>
>And here, it's worse.  If you fake it with a cast or by writing a fake
>prototype, you're likely to get the wrong answer, on machines where int and
>long have different sizes.  Again, I see no advantage of int32 over long.
>

I'm concerned, at the instant, with precisely three machines:

machine		int 		long		size_t		int32
---------------------------------------------------------------------
sun et. al.	32		32		int		int
PC		16		32		long		long
RS/6000		32		32		unsigned long	long

This works a lot better than using long. 

1) when I need to specify the layout for data that is stored on disk
or transported across the net, and I want 32 bits, just like in a TCP
packet, I say "int32." 

2) when I go to pass a value to a system routine that takes an "int"
on the sun, I don't get whining and complaining about passing a long
to an int.

If I said "int" case (1) would break on the PC. If I said "long" I'd get
warnings on the sun. And some things are really just integers, they
don't have any abstract nature at all.

If I have to deal with 36 or 24 or whatever, I'll have a harder
problem to hack. No question. 


-- 
Benson I. Margulies



More information about the Comp.lang.c mailing list