"Barry Schwarz" <sc******@dqel. comwrote in message
news:1t******** *************** *********@4ax.c om...
On Sun, 1 Jun 2008 19:56:33 -0400, "Bill Leary" <Bi********@msn .com>
wrote:
>>Sure. But since the specific question was why he got four bytes rather
than
two in the target file I emphasized that 2 * 2 is 4, and alluded your
point
by commenting "More or less..." and mentioning the crash.
But once the OP has invoked undefined behavior, there is no guarantee
that 2*2 will still equal 4. The only reason fwrite produced 4 bytes
is that this particular manifestation of undefined behavior produced 4
bytes. The fact that he inadvertently asked for 4 bytes is only
unfortunate coincidence. The next time it executes it could do
something completely different. If the OP were to recompile with
different options, who knows what the code could do.
You are both technically and theoretically correct.
The root issue, however, was that he was telling the function to write four
bytes when he thought he was telling it to write two bytes.
Explaining the potentially world shattering side effects* of what might have
happened due to his misunderstandin g invoking "undefined behavior" would
hardly have been profitable. What he needed, and asked for, was an
explanation of what actually did happen.
If you want to go on in the "undefined behavior" vein, please do so.
Someone has to fight the Good Fight, and you seem to understand your topic
well and do it with great verve.**
For me, I'm done.
- Bill
______________
* I recall someone in another "undefined behavior" thread saying that the
program was free to do anything at all, including implode the world, if it
so desired.
** Yeah, I'm being a little sarcastic. But just a little. I've just
re-examined a half dozen messages where you made your "undefined behavior"
spiel and in each of them (as far as I could tell) you were dead on correct.
An impressive accomplishment.