c,c++

A

Army1987

There is one thing we know about C/C++ : it invokes undefined behaviour in
both C and C++.

Sure? C is only modified once...
Unless C is 0, a NaN, or an infinity, it is equivalent to (++C, 1).
Or is it?
 
C

Charlie Gordon

Army1987 said:
Sure? C is only modified once...
Unless C is 0, a NaN, or an infinity, it is equivalent to (++C, 1).
Or is it?

No, it isn't.
Why should the numerator be evaluated before the denominator and its
side-effects ?
For C=1, the expression could evaluate to 2, with C=-2 you would get 0.

C/C++ invokes undefined behaviour.
 
F

Flash Gordon

Charlie Gordon wrote, On 17/09/07 15:37:
No, it isn't.
Why should the numerator be evaluated before the denominator and its
side-effects ?
For C=1, the expression could evaluate to 2, with C=-2 you would get 0.

C/C++ invokes undefined behaviour.

Of course, the reason the behaviour is undefined has nothing to do with
order of evaluation. It is because C is modified and read for a purpose
other than determining the new value of C with no intervening sequence
point.
 
C

Charlie Gordon

Flash Gordon said:
Charlie Gordon wrote, On 17/09/07 15:37:

Of course, the reason the behaviour is undefined has nothing to do with
order of evaluation. It is because C is modified and read for a purpose
other than determining the new value of C with no intervening sequence
point.

I did not pretend it did. You gave the formal reason as stated in the
Standard. I merely gave a practical example of why behaviour cannot be
defined. Evaluation could occur in no particular order, or in parallel, or
not occur at all.
 
O

Old Wolf

I merely gave a practical example of why behaviour cannot be defined.

Your example does not show that. Unspecified behaviour
would be consistent with your example. In fact, so would
defined behaviour.
 
C

Charlie Gordon

Old Wolf said:
Your example does not show that. Unspecified behaviour
would be consistent with your example. In fact, so would
defined behaviour.

Correct: the order of evaluation is "unspecified". So I did not adequately
show that behaviour was undefined. Flash Gordon did.
 

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

Similar Threads

Anyone interested in LearningForth with me? 0
Blue J Ciphertext Program 2
Good Morning 1
Beginner at c 0
My Status, Ciphertext 2
Python battle game help 2
THE PROGRAM IS NOT RUNING 3
C exercise 1

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top