J
jaysome
It's easier to write %d and (int) in ten line programs whose whole
purpose is to print structure member offsets. Note that the
program *was* correct (there doesn't exist a computer where
2*sizeof(double)+2*sizeof(long)+padding > INTMAX).
Besides, ironically, cast to unsigned long is almost as bad
as cast to int. If implementation was sufficiently weird (which
it isn't), both could break. unsigned long is as correct
as int: both can break (in weird theory); both ranges are smaller than
size_t range on some *existing* implementations; both work on all
existing implementations. Once something goes out the int range,
it will break on win64 if you use long![]()
That is pretty much my thinking. Since it was basically a 10 line
program in which the structure members were basic types like char,
short, int, long and double, it's always safe to printf() the offsetof
these members using a conversion specifier of "%d" and casting the
arguments to int. Quick and dirty, yet effective.