comparing sizes of two structures

  • Thread starter subramanian100in
  • Start date
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top