Re: what's the meaning of the following expression?
From: David Mair (mairdanot_at_nothotmail.com)
Date: 08/05/04
- Next message: Carl Daniel [VC++ MVP]: "Re: How to include chinese characters in the source"
- Previous message: David Mair: "Re: DAMAGE message on free()"
- In reply to: Victor Bazarov: "Re: what's the meaning of the following expression?"
- Next in thread: Jeff F: "Re: what's the meaning of the following expression?"
- Messages sorted by: [ date ] [ thread ]
Date: Wed, 04 Aug 2004 19:58:41 -0600
Victor Bazarov wrote:
> "David Mair" <mairdanot@nothotmail.com> wrote...
>
>>sjtu_huang wrote:
>>
>>
>>>i=(bSuccess) ? a:(b,c);
>>>especially what's the meaning of "(b,c)"?
>>
>>Here's how I understand it. b and c are evaluated from left to right
>>and the value of the group is the value of the rightmost expression - c.
>> All side-effects take place for each expression before the next
>>expression is evaluated. For example:
>>
>>a = 1;
>>b = 2;
>>c = 3;
>>bSuccess = false;
>>
>>With the expression above i takes the value 3, the value of c. It's
>>utility probably makes more sense for an example like this:
>>
>>i = (bSuccess) ? a : (b++, c);
>>
>>b is evaluated (incremented for this example) before c is evaluated and
>>the result of the expression is c. Or:
>>
>>i = (bSuccess) ? a : (b++, c + b);
>>
>>This one is more interesting in that the value of the group is the value
>>of c plus the incremented value of b.
>>
>>You can use more than one comma to have more than two expressions but
>>the rightmost one is the value of the group.
>>
>>The comma operator is used for function arguments.
>
>
> Please don't spread confusion. The comma seen in the list of function
> arguments in a function call has NOTHING to do with the comma operator
> except the use of the same character. The most significant difference
> between the two is that the operands of the comma operator are always
> evaluated from left to right and there is a sequence point between them
> while the order of evaluation of function arguments is _unspecified_ in
> C++.
Sorry, mis-read the MSDN Library page, it couldn't be clearer really:
"Commas can be used as separators in some contexts, such as function
argument lists. Do not confuse the use of the comma as a separator with
its use as an operator; the two uses are completely different."
I read the first paragraph then the examples, the paragraph above is in
between.
- Next message: Carl Daniel [VC++ MVP]: "Re: How to include chinese characters in the source"
- Previous message: David Mair: "Re: DAMAGE message on free()"
- In reply to: Victor Bazarov: "Re: what's the meaning of the following expression?"
- Next in thread: Jeff F: "Re: what's the meaning of the following expression?"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|