473,394 Members | 1,971 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Question regarding sequence point in case of conditional operator



Hi All,

I have one question regarding the conditional operator.
In the draft C99 standard it is mentioned that

"1 The following are the sequence points described in 5.1.2.3:
-- The call to a function, after the arguments have been evaluated
(6.5.2.2).
-- The end of the first operand of the following operators: logical AND
&& (6.5.13);
logical OR || (6.5.14); conditional ? (6.5.15); comma , (6.5.17)."

My question is conditional operator consist of "?" and ":" . Now if
I try to modify the value of one particular variable between "?" and
": " will it show undefined behavior?
For example

b = (a++)? a++: a++;
Here is the second increment of a++ will be undefined?

Regards,
Somenath
Dec 14 '07 #1
3 2436
somenath wrote:
I have one question regarding the conditional operator.
In the draft C99 standard it is mentioned that

"1 The following are the sequence points described in 5.1.2.3:
-- The call to a function, after the arguments have been evaluated
(6.5.2.2).
-- The end of the first operand of the following operators: logical AND
&& (6.5.13);
logical OR || (6.5.14); conditional ? (6.5.15); comma , (6.5.17)."

My question is conditional operator consist of "?" and ":"
Well, no, it has three expressions in there also: `test ? ifso : ifnot`.
There's a sequence point after the first operand, ie, `test`. The second
(or third) operand is [as if it is] evaluated once the test is completed.
. Now if
I try to modify the value of one particular variable between "?" and
": " will it show undefined behavior?
For example

b = (a++)? a++: a++;
Here is the second increment of a++ will be undefined?
No. Why do you think it might be?

--
Chris "see Quen's point?" Dollin

Hewlett-Packard Limited Cain Road, Bracknell, registered no:
registered office: Berks RG12 1HN 690597 England

Dec 14 '07 #2
On Dec 14, 3:19 pm, Chris Dollin <chris.dol...@hp.comwrote:
somenath wrote:
I have one question regarding the conditional operator.
In the draft C99 standard it is mentioned that
"1 The following are the sequence points described in 5.1.2.3:
-- The call to a function, after the arguments have been evaluated
(6.5.2.2).
-- The end of the first operand of the following operators: logical AND
&& (6.5.13);
logical OR || (6.5.14); conditional ? (6.5.15); comma , (6.5.17)."
My question is conditional operator consist of "?" and ":"

Well, no, it has three expressions in there also: `test ? ifso : ifnot`.
There's a sequence point after the first operand, ie, `test`. The second
(or third) operand is [as if it is] evaluated once the test is completed.
. Now if
I try to modify the value of one particular variable between "?" and
": " will it show undefined behavior?
For example
b = (a++)? a++: a++;
Here is the second increment of a++ will be undefined?

No. Why do you think it might be?
Sorry for posting the same question twice.
In the standard it specifically says about "conditional ? (6.5.15);"
So I had the doubt that is it true for ":" also ?

Dec 14 '07 #3
"somenath" <so*********@gmail.comschrieb im Newsbeitrag
news:31**********************************@s8g2000p rg.googlegroups.com...
On Dec 14, 3:19 pm, Chris Dollin <chris.dol...@hp.comwrote:
>somenath wrote:
I have one question regarding the conditional operator.
In the draft C99 standard it is mentioned that
"1 The following are the sequence points described in 5.1.2.3:
-- The call to a function, after the arguments have been evaluated
(6.5.2.2).
-- The end of the first operand of the following operators: logical AND
&& (6.5.13);
logical OR || (6.5.14); conditional ? (6.5.15); comma , (6.5.17)."
My question is conditional operator consist of "?" and ":"

Well, no, it has three expressions in there also: `test ? ifso : ifnot`.
There's a sequence point after the first operand, ie, `test`. The second
(or third) operand is [as if it is] evaluated once the test is completed.
. Now if
I try to modify the value of one particular variable between "?" and
": " will it show undefined behavior?
For example
b = (a++)? a++: a++;
Here is the second increment of a++ will be undefined?

No. Why do you think it might be?

Sorry for posting the same question twice.
In the standard it specifically says about "conditional ? (6.5.15);"
So I had the doubt that is it true for ":" also ?
It seem irrelevant whether ":" is a sequence point, it does separate the
"if" from the "else" branch, so only one of the statements get
executed/evaluated anyway. Then finally the ; gets hit, which again is a
sequence point.
Bye, Jojo
Dec 14 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Sensorflo | last post by:
After browsing though many newsgroups articels I'm still not shure how operator precedence, operator associativity, sequence points, side effects go together. Currently I have the following view: ...
8
by: der | last post by:
Hello all, I've a question about order of evaluations in expressions that have && and || operators in them. The question is: will the evalution go left-to-right, no matter what -- even if the...
6
by: Bo Sun | last post by:
hi: please take a look at the following code: int p={111, 222, 333, 444}, *q = p, p1, p2, p3; p1 = *q++; p2 = *(q++); p3 = *(++q);
9
by: Tim Rentsch | last post by:
I have a question about what ANSI C allows/requires in a particular context related to 'volatile'. Consider the following: volatile int x; int x_remainder_arg( int y ){ return x % y; }
7
by: Kenneth Brody | last post by:
(From something brought up on "Help with array/pointer segmentation fault needed" thread.) Is "?" a sequence point? Or, more directly, is the following defined? /* Will "ptr" be guaranteed...
15
by: Jeroen | last post by:
Hi all, I've got a very specific question about the evaluation order in C++. Assume some kind of custom array class, with an overloaded subscript operator. In the following code: { my_array...
8
by: JackC | last post by:
Hi, I am trying to get posix threads working from within an object, heres some code: int NConnection::TheadControl() { int thread_id; pthread_t new_connection;...
17
by: somenath | last post by:
Hi All, I have one question regarding the bellow mentioned code #include<stdio.h> int main(void) { int x = 0; int y = 0;
0
by: somenath | last post by:
Hi All, I have one question regarding the conditional operator. In the draft C99 standard it is mentioned that "1 The following are the sequence points described in 5.1.2.3: -- The call to a...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.