Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Question regarding sequence point in case of conditional operator

Reply
Thread Tools

Question regarding sequence point in case of conditional operator

 
 
somenath
Guest
Posts: n/a
 
      12-14-2007


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


 
Reply With Quote
 
 
 
 
Chris Dollin
Guest
Posts: n/a
 
      12-14-2007
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

 
Reply With Quote
 
 
 
 
somenath
Guest
Posts: n/a
 
      12-14-2007
On Dec 14, 3:19 pm, Chris Dollin <(E-Mail Removed)> wrote:
> 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 ?

 
Reply With Quote
 
Joachim Schmitz
Guest
Posts: n/a
 
      12-14-2007
"somenath" <(E-Mail Removed)> schrieb im Newsbeitrag
news:(E-Mail Removed)...
> On Dec 14, 3:19 pm, Chris Dollin <(E-Mail Removed)> wrote:
>> 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


 
Reply With Quote
 
pete
Guest
Posts: n/a
 
      12-14-2007
somenath wrote:

> > > In the draft C99 standard it is mentioned that


> In the standard it specifically says about "conditional ? (6.5.15);"
> So I had the doubt that is it true for ":" also ?


That's a typographical error.
The conditional operator has two parts, ? and :
like parentheses do, ( and )

This is the conditional operator as shown in the N869 index:
conditional operator (? , 6.5.15

In other parts of the draft, it's also written as ?:

6.5 Expressions

[#3] The grouping of operators and operands is indicated by
the syntax.61) Except as specified later (for the function-
call (), &&, ||, ?:, and comma operators), the order of
evaluation of subexpressions and the order in which side
effects take place are both unspecified.

61)
The exceptions are cast expressions (6.5.4) as operands
of unary operators (6.5.3), and an operand contained
between any of the following pairs of operators: grouping
parentheses () (6.5.1), subscripting brackets []
(6.5.2.1), function-call parentheses () (6.5.2.2), and
the conditional operator ?: (6.5.15).

--
pete
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Share-Point-2010 ,Share-Point -2010 Training , Share-point-2010Hyderabad , Share-point-2010 Institute Saraswati lakki ASP .Net 0 01-06-2012 06:39 AM
Question regarding sequence point in case of conditional operator somenath C Programming 0 12-14-2007 10:01 AM
Question regarding sequence point somenath C Programming 4 11-26-2007 06:29 AM
Scenario 5: IS-IS routing on Frame Relay Multi-point and Point-to-Point David Sudjiman Cisco 0 06-08-2006 09:11 AM
? ELSE Conditional Comment / Using Conditional Comments Inside Other Tags To Comment Out Attributes Alec S. HTML 10 04-16-2005 02:21 AM



Advertisments