Tim Rentsch said:
Keith Thompson said:
[snip]
If the standard did have the requirement you mention: "Do not call
va_end after va_start unless va_arg has been called to process
every argument in the calling sequence", what great inconvenience
would it cause?
The problem is it requires us to know things that we may
not know, namely, the number and types of arguments remaining.
Even if a motivating example isn't immediately obvious, that's
a chilling prospect.
The quoted discussion was a while ago, but I think what I had in mind is
that calling va_end "too soon" would have undefined behavior. For
example (assuming printf uses the <stdarg.h> mechanism), this:
printf("%s\n", "arg1", "ignored");
has well defined behavior; with the hypothetical rule, its behavior
would be undefined.
That's an issue right there. We are taking a statement that
has defined behavior now and changing the language so it has
undefined behavior. Don't you see a problem with that?
I would certainly see a problem with that if that were what I suggested.
I'm not talking about changing the language; I'm speculating about what
problems, if any, would have resulted if the language had been defined
that way from the beginning.
When C was standardized in 1989, it *could have* been defined so that
excess arguments cause undefined behavior. If it had, I don't believe
it would have caused any great inconvenience. (Changing it now *would*
cause great inconvenience.)