jacob navia said:
Irrelevant heathfield, completely irrelevant. Non
prototyped functions are assumed returning an int.
So what?
printf is a variadic function. Calling a variadic function with no
prototype in scope invokes undefined behavior. Without a prototype, a
function is assumed, in C90, to be a function returning int and taking
a fixed but unspecified number and type of arguments; printf does not
qualify. An implementation could use a completely different calling
convention for variadic functions than for non-variadic functions. If
you call a variadic function using a non-variadic calling convention,
it could easily fetch an argument value from the wrong location. One
possible result: printf prints 42 even though i==0.
It will happen to "work" on many implementations, but it is not
required to.
Yes, and so what?
Nowhere is specified that the behavior is
undefined. It has an UNDEFINED VALUE heathfield but the
program is not "undefined" nor it invokes "undefined behavior"
Talking nonsense again.
Take a look at the standard. It talks about "undefined behavior"; the
phrase "undefined value" appears nowhere in the standard. See also
"implementation-defined value", "indeterminate value", "unspecified
value", and "trap representation".
Suppose type int has one or more trap representations. Suppose an
uninitialized int object happens to have a trap representation. (An
implementation could do this deliberately, for the purpose of catching
errors as early as possible.) The result of reading a variable with a
trap representation is undefined behavior. The standard says so quite
clearly.
[snip]