Output undefined?

N

no

main()
{
int i;
printf("%d %d",i++,++i);
}

Is the output undefined?

int main #include crap etc. is understood.
 
R

Richard Bos

Nils Petter Vaskinn said:
Yes because you have never given i a value.

And that's before considering in which order i++ and ++i will be evaluated.

Order is immaterial; the mere occurence of them both together between
sequence points invokes undefined behaviour.

If either of you had read the FAQ, you'd have known this:
<http://www.eskimo.com/~scs/C-faq/q3.2.html>.

Richard
 
D

Dan Pop

Read the FAQ!
Yes because you have never given i a value.

And that's before considering in which order i++ and ++i will be evaluated.

The evaluation order does NOT matter. What matters is the lack of a
sequence point between these two expressions. So, instead of having an
unspecified output (assuming a properly initialised i) we have undefined
behaviour for the whole program. The FAQ clearly explains these issues!

Dan
 
J

Jack Klein

main()
{
int i;
printf("%d %d",i++,++i);
}

Is the output undefined?

int main #include crap etc. is understood.

Yes, even if you initialized I with a value. There is no sequence
point in the evaluation of arguments to functions, so your code
modifies i twice without an intervening sequence point.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++ ftp://snurse-l.org/pub/acllc-c++/faq
 
J

Joona I Palaste

It would have taken less typing to just to do it right in the first
place.

I agree. I detect a shade of DAISNAID. Oh, sorry, forgot that
abbreviations are frowned upon here. "Do As I Say, Not As I Do".

--
/-- Joona Palaste ([email protected]) ---------------------------\
| Kingpriest of "The Flying Lemon Tree" G++ FR FW+ M- #108 D+ ADA N+++|
| http://www.helsinki.fi/~palaste W++ B OP+ |
\----------------------------------------- Finland rules! ------------/
"You have moved your mouse, for these changes to take effect you must shut down
and restart your computer. Do you want to restart your computer now?"
- Karri Kalpio
 

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,767
Messages
2,569,571
Members
45,045
Latest member
DRCM

Latest Threads

Top