Richard Heathfield said:
I suppose I'd better say it before he does - there is ONE exception
to (1), the VLA thing, and of course that exception doesn't apply
to struct tm anyway so is of no consequence in this discussion.
Please correct any errors in the following coda.
Given the following C99 function,
int oogabooga (int n) {
int vla[n];
return sizeof *vla;
}
The length of the array (variable here, but the same otherwise)
has no bearing upon the value of the expression (sizeof *vla)
as only a single element is referenced. The return value of
this function is therefore a compile-time constant, requiring
0 run-time to compute. As it's such a small number, on all
but the strangest machines it could be an immediate operand
embedded into the machine instruction.
In this nasty
int booger (int n) {
int vla[n];
return sizeof vla;
}
The size of an individual element is known at compile time,
and the size of the whole array is therefore merely n * how-
big-an-int-may-be. Surely the compiler would use a multiplication
or shift instruction. Nothing to dereference. No "evaluation".
In lisp parlance, I believe one would say the operands of
sizeof are implicitly quoted.
With normal, compiled, C, sizeof doesn't actually *do* anything.
It's merely an arithmetic shorthand for a compile-time constant
or (in the one exception) a multiplication.
IMO FWIW HTH YMMV IIRC AMEN