K
Keith Thompson
It doesn't need to: there's a built-in "t" modifier.
Thanks, I had missed that one!
It doesn't need to: there's a built-in "t" modifier.
Eric said:By happenstance, by chance, by pure dumb luck. If you
wear a blindfold while driving a car, it is possible that
your journey will be uneventful.
pete said:Keith said:Converting the ptrdiff_t result of the subtraction to int isstruct whatever array[2];
unsigned char *first = (unsigned char *)&array[0];
unsigned char *second = (unsigned char *)&array[1];
printf("%d\n", (int)(second - first));
unnecessary. It's possible (if unlikely) that sizeof(struct whatever)
could exceed INT_MAX.
Shouldn't the possibility that sizeof(struct whatever)
could exceed INT_MAX,
be the reason why converting the ptrdiff_t result
of the subtraction to int is *necessary*?
Keith Thompson said:It's possible that ptrdiff_t could be a typedef for short (though I
know of no real-world system where this is the case). On such a
system (or on any system where ptrdiff_t is a typedef for something
other than int), this:
printf("%d\n", second - first);
invokes undefined behavior.
srikar2097 said:Are you sure the METHOD 1 given by me does not work?
I ran the program and got the size as 8bytes.
Then I ran the program using the sizeof() and got the size as 8
bytes.
Is this a coincidence? This method works. If in doubt you could try it
yourself.
Surely the short will have been promoted to an int.
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.