Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > comma

Reply
Thread Tools

comma

 
 
JKop
Guest
Posts: n/a
 
      11-05-2004

void Blah(int k) { k; }


int main()
{
int a;
int b;

Blah( ++a, ++b );
}


Is there any rules to say in what way a comma is interpreted within function
arguments?

If I were to guess, I'd say that it's always interpreted as an argument
seperator, except when enclosed in its own brackets, as in:


void Blah(int k) { k; }


int main()
{
int a;
int b;

Blah( (++a, ++b) );
}


But then again I'm just guessing!


-JKop
 
Reply With Quote
 
 
 
 
Gernot Frisch
Guest
Posts: n/a
 
      11-05-2004

"JKop" <> schrieb im Newsbeitrag
news:ZgIid.40966$...
>
> void Blah(int k) { k; }
>
>
> int main()
> {
> int a;
> int b;
>
> Blah( ++a, ++b );
> }
>
>
> Is there any rules to say in what way a comma is interpreted within
> function
> arguments?
>
> If I were to guess, I'd say that it's always interpreted as an
> argument
> seperator, except when enclosed in its own brackets, as in:
>
>
> void Blah(int k) { k; }
>
>
> int main()
> {
> int a;
> int b;
>
> Blah( (++a, ++b) );
> }
>
>
> But then again I'm just guessing!


The , is an operator with highest prescendence (will be evaluated at
very last, even after braces). It simply divides operations, but does
not change the lvalue nor the rvalue.

Common example:
for (int i=0, j=5; i<5; i++, j++) {}

Was that your question?
-Gernot



 
Reply With Quote
 
 
 
 
JKop
Guest
Posts: n/a
 
      11-05-2004
Gernot Frisch posted:

>
> "JKop" <> schrieb im Newsbeitrag
> news:ZgIid.40966$...
>>
>> void Blah(int k) { k; }
>>
>>
>> int main()
>> {
>> int a;
>> int b;
>>
>> Blah( ++a, ++b ); }
>>
>>
>> Is there any rules to say in what way a comma is interpreted within
>> function arguments?
>>
>> If I were to guess, I'd say that it's always interpreted as an
>> argument seperator, except when enclosed in its own brackets, as in:
>>
>>
>> void Blah(int k) { k; }
>>
>>
>> int main()
>> {
>> int a;
>> int b;
>>
>> Blah( (++a, ++b) ); }
>>
>>
>> But then again I'm just guessing!

>
> The , is an operator with highest prescendence (will be evaluated at
> very last, even after braces). It simply divides operations, but does
> not change the lvalue nor the rvalue.
>
> Common example:
> for (int i=0, j=5; i<5; i++, j++) {}
>
> Was that your question?
> -Gernot


Consider a function that takes ONE argument. You call it as so:


Func( a, b );


What are the rules to dictate whether the function has been supplied:

A) Two arguments

- First argument: a
- Second argument: b


B) One argument

- First argument: a, b


-JKop
 
Reply With Quote
 
John Harrison
Guest
Posts: n/a
 
      11-05-2004

"JKop" <> wrote in message
news:ZgIid.40966$...
>
> void Blah(int k) { k; }
>
>
> int main()
> {
> int a;
> int b;
>
> Blah( ++a, ++b );
> }
>
>
> Is there any rules to say in what way a comma is interpreted within

function
> arguments?
>
> If I were to guess, I'd say that it's always interpreted as an argument
> seperator, except when enclosed in its own brackets, as in:
>
>
> void Blah(int k) { k; }
>
>
> int main()
> {
> int a;
> int b;
>
> Blah( (++a, ++b) );
> }
>
>
> But then again I'm just guessing!
>


I think you guess right, but then again I am only guessing.

The rule you are talking about definitely applies to macro invocations I
don't see why it shouldn't apply to function calls as well.

john


 
Reply With Quote
 
Ron Natalie
Guest
Posts: n/a
 
      11-05-2004
JKop wrote:
rnot
>
>
> Consider a function that takes ONE argument. You call it as so:
>
>
> Func( a, b );
>
>
> What are the rules to dictate whether the function has been supplied:
>
> A) Two arguments
>
> - First argument: a
> - Second argument: b
>

A. The language grammar says that the comma in the above is always
the punctuation separating the function call. It doesn't matter
how Func is declared (it can't really consider that anyhow, the
whole overload process depends on knowing the function signature
first).
 
Reply With Quote
 
David Lindauer
Guest
Posts: n/a
 
      11-05-2004
',' in an argument list is not considered the same as ',' in general usage. So
if you use it in an argument list, it separates the arguments, unless you do as
you suggest and put it in parenthesis (there are a number of such
context-dependent usages for symbols in the language)

David

JKop wrote:

> void Blah(int k) { k; }
>
> int main()
> {
> int a;
> int b;
>
> Blah( ++a, ++b );
> }
>
> Is there any rules to say in what way a comma is interpreted within function
> arguments?
>
> If I were to guess, I'd say that it's always interpreted as an argument
> seperator, except when enclosed in its own brackets, as in:
>
> void Blah(int k) { k; }
>
> int main()
> {
> int a;
> int b;
>
> Blah( (++a, ++b) );
> }
>
> But then again I'm just guessing!
>
> -JKop

 
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
How to format $mail_from with 2 variables separated by a comma? Jason Miles Perl 1 05-28-2004 02:48 AM
Decimal point is replaced with comma Rasool ASP .Net 3 03-03-2004 06:02 PM
Comma Delimited Yama ASP .Net 1 12-16-2003 03:46 AM
server.mappath with comma in foldername? Martin Pahlplatz ASP .Net 0 11-11-2003 10:08 PM
add a comma Ryan Moore ASP .Net 4 08-28-2003 03:32 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57