Subject: Re: example for k&r being bad (was: Re: Bluetooth protocol code)
To: None <>
From: der Mouse <mouse@Rodents.Montreal.QC.CA>
List: tech-userlevel
Date: 12/20/2005 01:43:11
>> int pr(x,y) long int x; int y;
>> { printf("%ld %d\n",x,y); }
>> int main(ac,av) int ac; char **av;
>> { pr(1,2); return(0); }
>> when long occupies more argument-list space than int, you get
>> brokenness - probably either 4294967298 or 8589934593, followed by a
>> "random" value that generally comes from uninitialized stack trash.
> output on i386:  1 2
> output on alpha: 1 2

> Next try? :)

Check the assembly code - you'll probably find both arguments are
passed in registers on the alpha, so "when long occupies more
argument-list space than int" does not apply.  That's certainly what I
see when I try it on my alpha (but with a compiler that I feel sure is
much older than what you're using).

The kind of code that causes practical problems on the alpha is code
that, for example, assumes you can stuff a pointer into an int and then
retrieve it later unmutilated.  (The only safe ways I know of to do
something like this are to use a union or to use sizeof() and chars.)
Or code that assumes a an unsigned long in decimal takes no more than
ten digits.  Or....

/~\ The ASCII				der Mouse
\ / Ribbon Campaign
 X  Against HTML
/ \ Email!	     7D C8 61 52 5D E7 2D 39  4E F1 31 3E E8 B3 27 4B