On 8/25/2010 8:53 AM, Mister B wrote:
> I have come across some code that has been working for years, in which
> function A calls function B and passes a parameter, but function B
> does not expect any parameters!
> (Obviously there was no prototype for B, an oversight which is being
> corrected. With full warnings on, gcc warns of "implicit declaration"
> which was the clue).
>
> Anyway, my question is: what type of problems might this have been
> causing?
>
> I know, I know, you'll tell me nasal daemons and anything at all etc
> etc, but thnking about some typical implementations, might there be
> some data hanging around on a stack or something that could get future
> data out of sync, or would anything get cleared on exit from B?
Okay, you've already heard the "In principle, anything can
happen" argument, and have decided to discount it. That's fine,
to a point, but keep in mind that even if *every* implementation
*today* acts in a certain way, that doesn't prove that tomorrow's
super-desirable implementation trick will work. "Sorry, sir, but
your code won't work with Frobozz Magic C unless you specify the
-dumbass flag, which causes an eight- to forty-fold slowdown."
But anyhow: Some systems have used (or use today, for all I
know) calling conventions in which the responsibility for stack
(or more generally, "argument") housekeeping is divided between
caller and callee, each side bearing part of the responsibility.
If the caller says "I'm pushing two arguments and I know the called
function will clean them up," while the callee says "I'm receiving
one argument and must dispose of it before returning," you've got
a recipe for disaster: `for (i = 0; i < 100000000; ++i) f(i,x);'
will almost certainly die with a stack overflow, if not worse.
"Bless you, it all depends!" -- Pitti-Sing
--
Eric Sosman
lid