Re: C Test Incorrectly Uses printf() - Please Confirm
- From: Keith Thompson <kst-u@xxxxxxx>
- Date: Tue, 10 Aug 2010 09:26:26 -0700
Tom St Denis <tom@xxxxxxx> writes:
[...]
All I read that as is the value of 'a + 5' is not defined. All the
work up to that point IS defined. computing an expression like 'a +
5' can have no side effects in this application since it's either 6 or
7 which are both valid 'int' values [no overflow].
I get what you're saying that since the ENTIRE statement is not
composed of defined expressions it's rejected as UB, but if we speak
practically for a second, it's a throwaway statement that can't have
side effects [other than taking time to compute].
In fact, since it's not even printed out it could just optimize out
the expression altogether.
I would therefore expect with every C compiler on this planet in
common use that the statement would print '2' as its output with
absolutely no undefined behaviour whatsoever. More so, I think this
is just a whole in the spec in which you have UB but it could be
defined [or at least mitigated] with a bit of logical deduction.
The real point of undefined behavior is not that any real-world
implementation is likely to behave in any particular way. The point --
what "undefined behavior" *means* -- is that, if a program executing the
statement
printf("%d", ++a, a + 5);
prints "kablooie" or emits a suffusion of yellow, that doesn't
imply that the implementation is non-conforming. The Standard
"imposes no requirements"; that's all it means.
[...]
--
Keith Thompson (The_Other_Keith) kst-u@xxxxxxx <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
.
- Follow-Ups:
- Re: C Test Incorrectly Uses printf() - Please Confirm
- From: Tom St Denis
- Re: C Test Incorrectly Uses printf() - Please Confirm
- References:
- C Test Incorrectly Uses printf() - Please Confirm
- From: Martin O'Brien
- Re: C Test Incorrectly Uses printf() - Please Confirm
- From: Shao Miller
- Re: C Test Incorrectly Uses printf() - Please Confirm
- From: Shao Miller
- Re: C Test Incorrectly Uses printf() - Please Confirm
- From: Willem
- Re: C Test Incorrectly Uses printf() - Please Confirm
- From: Tom St Denis
- Re: C Test Incorrectly Uses printf() - Please Confirm
- From: Eric Sosman
- Re: C Test Incorrectly Uses printf() - Please Confirm
- From: Tom St Denis
- C Test Incorrectly Uses printf() - Please Confirm
- Prev by Date: C vs. Fortran (half OT questions)
- Next by Date: Re: OT: Re: in your opinion
- Previous by thread: Re: C Test Incorrectly Uses printf() - Please Confirm (NULL ptr. deref. cross-over episode)
- Next by thread: Re: C Test Incorrectly Uses printf() - Please Confirm
- Index(es):