Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Re: comma operator

Reply
Thread Tools

Re: comma operator

 
 
Keith Thompson
Guest
Posts: n/a
 
      05-15-2009
Franken Sense <(E-Mail Removed)> writes:
> In Dread Ink, the Grave Hand of Franken Sense Did Inscribe:
> [misposted to clp.misc]
> [x-posted to clc; f-up set to clc]
>> I'm reading up on perl today and find this in perldoc perlop:
>>
>> Comma Operator
>>
>> Binary "," is the comma operator. In scalar context it
>> evaluates its left argument, throws that value away, then
>> evaluates its right argument and returns that value. This is
>> just like C's comma operator.
>>
>> // end excerpt
>>
>> What is C's comma operator?


It evaluates its left argument, throws that value away, then evaluates
its right argument and yields that value.

See your C textbook.

(Note that not all commas are comma operators; in particular, the
commas separating arguments in a function call or macro invocation are
not operators.)

--
Keith Thompson (The_Other_Keith) http://www.velocityreviews.com/forums/(E-Mail Removed) <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
 
Reply With Quote
 
 
 
 
Franken Sense
Guest
Posts: n/a
 
      05-15-2009
In Dread Ink, the Grave Hand of Franken Sense Did Inscribe:

[misposted to clp.misc]
[x-posted to clc; f-up set to clc]
> I'm reading up on perl today and find this in perldoc perlop:
>
> Comma Operator
>
> Binary "," is the comma operator. In scalar context it evaluates its
> left argument, throws that value away, then evaluates its right
> argument
> and returns that value. This is just like C's comma operator.
>
> // end excerpt
>
> What is C's comma operator?



--
Frank

My father grew up in the Great Depression - his mother's.
~~ Al Franken
 
Reply With Quote
 
 
 
 
James Dow Allen
Guest
Posts: n/a
 
      05-15-2009
On May 15, 8:46*am, Keith Thompson <(E-Mail Removed)> wrote:
> (Note that not all commas are comma operators; in particular, the
> commas separating arguments in a function call or macro
> invocation are not operators.)


I've wondered if my rule is correct:
The comma in
A, B
is The Comma Operator if and only that is equivalent to
(A, B)

For example, only the second comma in
printf(A, (B, C))
is The Comma Operator because that is equivalent to
printf(A, ((B, C)))
but not
printf((A, (B, C)))

James
 
Reply With Quote
 
luserXtrog
Guest
Posts: n/a
 
      05-15-2009
On May 15, 2:49*am, James Dow Allen <(E-Mail Removed)> wrote:
> On May 15, 8:46*am, Keith Thompson <(E-Mail Removed)> wrote:
>
> > (Note that not all commas are comma operators; in particular, the
> > commas separating arguments in a function call or macro
> > invocation are not operators.)

>
> I've wondered if my rule is correct:
> The comma in
> * * *A, B
> is The Comma Operator if and only that is equivalent to
> * * *(A, B)
>
> For example, only the second comma in
> * * *printf(A, (B, C))
> is The Comma Operator because that is equivalent to
> * * *printf(A, ((B, C)))
> but not
> * * *printf((A, (B, C)))
>
> James


I find it easier to think of the comma as a semicolon without
a period. It terminates the expression without terminating the
statement.

--
lxt
 
Reply With Quote
 
Keith Thompson
Guest
Posts: n/a
 
      05-15-2009
luserXtrog <(E-Mail Removed)> writes:
[...]
> I find it easier to think of the comma as a semicolon without
> a period. It terminates the expression without terminating the
> statement.


Ah, but it doesn't terminate the expression; it only terminates a
subexpression.

--
Keith Thompson (The_Other_Keith) (E-Mail Removed) <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
 
Reply With Quote
 
Willem
Guest
Posts: n/a
 
      05-15-2009
Richard Heathfield wrote:
) Yes, it does. An expression is "a sequence of operators and operands
) that specifies computation of a value, or that designates an object
) or a function, or that generates side effects, or that performs a
) combination thereof". A comma operator always terminates such a
) sequence.

So, what would you call this then:

((1, 2, 3) + (4, 5, 6))


SaSW, Willem
--
Disclaimer: I am in no way responsible for any of the statements
made in the above text. For all I know I might be
drugged or something..
No I'm not paranoid. You all think I'm paranoid, don't you !
#EOT
 
Reply With Quote
 
Keith Thompson
Guest
Posts: n/a
 
      05-15-2009
Richard Heathfield <(E-Mail Removed)> writes:
> Keith Thompson said:
>> luserXtrog <(E-Mail Removed)> writes:
>> [...]
>>> I find it easier to think of the comma as a semicolon without
>>> a period. It terminates the expression without terminating the
>>> statement.

>>
>> Ah, but it doesn't terminate the expression; it only terminates a
>> subexpression.

>
> Yes, it does. An expression is "a sequence of operators and operands
> that specifies computation of a value, or that designates an object
> or a function, or that generates side effects, or that performs a
> combination thereof". A comma operator always terminates such a
> sequence.


You're right, of course. (The standard's definition of "expression"
is broken, but that's a separate point.)

Incidentally, that's true only because the comma operator has a lower
precedence than any other operator.

--
Keith Thompson (The_Other_Keith) (E-Mail Removed) <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
 
Reply With Quote
 
Keith Thompson
Guest
Posts: n/a
 
      05-15-2009
Keith Thompson <(E-Mail Removed)> writes:
> Richard Heathfield <(E-Mail Removed)> writes:
>> Keith Thompson said:
>>> luserXtrog <(E-Mail Removed)> writes:
>>> [...]
>>>> I find it easier to think of the comma as a semicolon without
>>>> a period. It terminates the expression without terminating the
>>>> statement.
>>>
>>> Ah, but it doesn't terminate the expression; it only terminates a
>>> subexpression.

>>
>> Yes, it does. An expression is "a sequence of operators and operands
>> that specifies computation of a value, or that designates an object
>> or a function, or that generates side effects, or that performs a
>> combination thereof". A comma operator always terminates such a
>> sequence.

>
> You're right, of course. (The standard's definition of "expression"
> is broken, but that's a separate point.)
>
> Incidentally, that's true only because the comma operator has a lower
> precedence than any other operator.


I may be wrong about that. I'll think about it when I have more time.

--
Keith Thompson (The_Other_Keith) (E-Mail Removed) <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
 
Reply With Quote
 
Keith Thompson
Guest
Posts: n/a
 
      05-15-2009
Richard Heathfield <(E-Mail Removed)> writes:
> Willem said:
>> Richard Heathfield wrote:
>> ) Yes, it does. An expression is "a sequence of operators and
>> operands ) that specifies computation of a value, or that
>> designates an object ) or a function, or that generates side
>> effects, or that performs a ) combination thereof". A comma
>> operator always terminates such a ) sequence.
>>
>> So, what would you call this then:
>>
>> ((1, 2, 3) + (4, 5, 6))

>
> I would call 1 an expression, which is terminated by a comma
> operator.

[...]

I would call 1 an expression. But I wouldn't call it "a sequence of
operators and operands". Here it's an operand of the comma operator,
but in isolation:

1;

there are no operators, and therefore 1 is not an operand.

--
Keith Thompson (The_Other_Keith) (E-Mail Removed) <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
 
Reply With Quote
 
Willem
Guest
Posts: n/a
 
      05-15-2009
Richard Heathfield wrote:
) Willem said:
)> So, what would you call this then:
)>
)> ((1, 2, 3) + (4, 5, 6))
)
) I would call 1 an expression, which is terminated by a comma
) operator.
) I would call 2 an expression, which is terminated by a comma
) operator.
) I would call 4 an expression, which is terminated by a comma
) operator.
) I would call 5 an expression, which is terminated by a comma
) operator.
)
) I would call the whole thing an expression, too.
)
) What would you call these expressions?

Subexpressions, obviously. They're all parts of the whole thing,
which is an expression.

What I wanted to know is what you call the operands of the '+' operator.


SaSW, Willem
--
Disclaimer: I am in no way responsible for any of the statements
made in the above text. For all I know I might be
drugged or something..
No I'm not paranoid. You all think I'm paranoid, don't you !
#EOT
 
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
comma operator and assignment operator G Patel C Programming 4 02-08-2005 02:53 AM
the whys of the comma operator Michael Scarlett C Programming 8 06-19-2004 12:08 AM
Confused about the comma operator Derek C++ 6 04-13-2004 09:03 PM
Yet another comma operator question Koster C Programming 7 01-18-2004 01:07 AM
Overloading comma to give a concatenation operator: various problems Paul Davis C++ 7 07-17-2003 07:25 AM



Advertisments