17 Oct
2012
17 Oct
'12
5:41 a.m.
On Wed, Oct 17, 2012 at 09:26:35AM +0100, Phil Mayers wrote:
I guess if there's any doubt,
"%lu", (long)sizeof(...)
should be pretty safe.
Yuck. Cast of unsigned to signed :oP
Sorry, I meant "%lu", (unsigned long)sizeof(...) If "%zu", sizeof(...) is correct I'm happy with that too.
TBH it's a fairly theoretical argument; sizeof is used on objects whose size tends to be in the range 1-100k and specified at compile time. The odds of sizeof ever returning >2**31 are very, very remote, at least with current system architectures.
It's more about pushing the right size onto the stack for va_arg. If you push an 8-byte value when printf consumes 4-bytes, or vice versa, then it will screw up the following arguments. Regards, Brian.