Subject: example for k&r being bad (was: Re: Bluetooth protocol code)
To: Bill Studenmund <firstname.lastname@example.org>
From: Hubert Feyrer <email@example.com>
Date: 12/20/2005 06:27:54
[Please drop tech-kern@ on replies, I think this belongs on tech-userlevel@]
On Mon, 19 Dec 2005, Bill Studenmund wrote:
> The problem is that K&R prototypes won't work right if we pass in a
> parameter that's larger than an int. Like a long or a pointer on an LP64
> In such a case, the caller will turn the parameter into an int, truncating
> it. Worse yet, the caller will then pack other parameters in, not leaving
> enough space for what the caller will expect the parameter to be. Thus the
> callee will see two parameters mixed together in what it thinks is one
> parameter (by our style guide, it will get the parameters right), and a
> parameter at the end will be totally uninitialized.
> This behavior is why we're moving away from K&R parameters & prototypes.
I've tried to write a program that shows this, but didn't succeed.
The program I come up with (based on your description) is available at
, output on ILP32 (NetBSD/i386) is in , output on LP64
(NetBSD/alpha) is in . Obviously they are the same, so I must have
missed something. What is it?
I think it would be useful to have a smallish piece of code that we can
point people at and say "look, differences between architectures if
you use K&R"...