By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,615 Members | 1,961 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,615 IT Pros & Developers. It's quick & easy.

How to read "The lvalue-to-rvalue, array-to-pointer, and function-to-pointer standard conversionsare not applied to the left expressions"?

P: n/a
How to read "The lvalue-to-rvalue, array-to-pointer, and function-to-
pointer standard conversionsare not applied to the left expressions"?

In 5.18 Comma operator of the C++ standard, there is a rule:

"The lvalue-to-rvalue, array-to-pointer, and function-to-pointer
standard conversionsare not applied to the left expressions"

I could not understand what the rule means. I also searched the web
and the groups and got nothing.

Who can give me some tips? Many thanks in advance.

Jun 21 '07 #1
Share this Question
Share on Google+
6 Replies


P: n/a
On Jun 21, 4:33 am, Lighter <cqu...@gmail.comwrote:
How to read "The lvalue-to-rvalue, array-to-pointer, and function-to-
pointer standard conversionsare not applied to the left expressions"?
In 5.18 Comma operator of the C++ standard, there is a rule:
"The lvalue-to-rvalue, array-to-pointer, and function-to-pointer
standard conversions are not applied to the left expressions"
I could not understand what the rule means. I also searched the web
and the groups and got nothing.
Well, it means that the lvalue-to-rule, array-to-pointer and
function-to-pointer conversions are not applied to the left
operand of a comma operator. That seems clear enough, per se;
what part don't you understand?

In general, I can't really see how a conforming program could
tell whether they were applied or not. For example, if I write:

int array[ 10 ] ;

array, f() ;

how can I possibly know whether the type of the right operand of
the comma is int[10] or int*? And how can it matter?

I suppose that it is really only significant with regards to
whether the type must be complete, or whether there must be a
definition.

class C ;
C* pC ;

*pC, f()

is legal, but it wouldn't be if an lvalue-to-rvalue conversion
took place (since the standard requires a complete type any time
there is an lvalue-to-rvalue conversion). Similarly, given:

extern int g() ;
extern int a[] ;

g, f() ;
a, f() ;

I think (but I'm far from sure) the fact that the function to
pointer conversion doesn't take place on g means that g is not
used in this expression, and thus that no definition is
required. And the same thing holds for a, because the
array-to-pointer conversion doesn't take place.

At any rate, that's the only real relevance I can see.

--
James Kanze (GABI Software, from CAI) email:ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

Jun 21 '07 #2

P: n/a
Thank you very much, James.

Please see an example:

int a[2];
int* p;
int* p2 = (p = a, p++); // Note here, p = a is a array-to-pointer
conversion.

the code above can be compiled without any warning with VS 2005. Why?

What is the reason of the standard's making such a rule? That is what
I really want to see. Could give me an explaination?

Jun 21 '07 #3

P: n/a
Lighter wrote:
How to read "The lvalue-to-rvalue, array-to-pointer, and function-to-
pointer standard conversionsare not applied to the left expressions"?

In 5.18 Comma operator of the C++ standard, there is a rule:

"The lvalue-to-rvalue, array-to-pointer, and function-to-pointer
standard conversionsare not applied to the left expressions"

I could not understand what the rule means. I also searched the web
and the groups and got nothing.

Who can give me some tips? Many thanks in advance.
Generally, it's meaningless. Since the value is just discarded, the
conversions don't happen. I'm not sure how you'd tell if they were
to happen anyhow.

int scalar = 0;
int array[10] = { 0 };
void func();

int i = scalar , 0;
i = array , 0;
i = func , 0;

Means the value scalar isn't converted to an rvalue,
and array isn't converted to int*,
and func isn't converted to void (*)().

Jun 21 '07 #4

P: n/a
Ron Natalie wrote:
Lighter wrote:
>How to read "The lvalue-to-rvalue, array-to-pointer, and function-to-
pointer standard conversionsare not applied to the left
expressions"?

In 5.18 Comma operator of the C++ standard, there is a rule:

"The lvalue-to-rvalue, array-to-pointer, and function-to-pointer
standard conversionsare not applied to the left expressions"

I could not understand what the rule means. I also searched the web
and the groups and got nothing.

Who can give me some tips? Many thanks in advance.
Generally, it's meaningless. Since the value is just discarded, the
conversions don't happen. I'm not sure how you'd tell if they were
to happen anyhow.

int scalar = 0;
int array[10] = { 0 };
void func();

int i = scalar , 0;
i = array , 0;
i = func , 0;
I don't believe this should compile. You need parentheses around the
comma expressions.
>
Means the value scalar isn't converted to an rvalue,
and array isn't converted to int*,
and func isn't converted to void (*)().
Take a look at this program:
--------------------------------------
int main() {
int a;
a, 42;
}
--------------------------------------
IF lvalue-to-rvalue conversion were happening for 'a', then the program
would have undefined behaviour because 'a' is uninitialised. I don't
think there is any other real need/implication for the rule.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Jun 21 '07 #5

P: n/a
On Jun 21, 12:32 pm, Lighter <cqu...@gmail.comwrote:
Thank you very much, James.
Please see an example:
int a[2];
int* p;
int* p2 = (p = a, p++); // Note here, p = a is a array-to-pointer
conversion.
OK. I understand where your problem is.

"p = a" is not an array-to-pointer conversion, because the type
of "p = a" is int*; the type of an assignment expression is
always the type of the lvalue being assigned.

There is an array-to-pointer conversion *in* the expression, but
the expression itself isn't subject to the conversion: if the
results of "p = a" were an array, no conversion would take
place. The expression "a" is not the expression to the right of
the comma operator; the expression "p = a" is. The expression
"a" is the expression to the left of an assignment operator,
where the rvalue to lvalue conversion takes place (which
automatically means that the array-to-pointer conversion is
active).
the code above can be compiled without any warning with VS 2005. Why?
Because it's legal.
What is the reason of the standard's making such a rule? That is what
I really want to see. Could give me an explaination?
See above. The text concerns only the operands of the comma
operator. The sub-expressions of that expression are not
concerned.

--
James Kanze (GABI Software, from CAI) email:ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
Jun 21 '07 #6

P: n/a
James. I'm grateful to you for your timely and helpful reply. However,
I am still not clear. Maybe I didn't correctly describe my problem. So
I reworded my problem and started a new thread at:
http://groups.google.com/group/comp....037a6653?hl=en

Please visit the post and give your precious tips. Thanks in advance.

Jun 21 '07 #7

This discussion thread is closed

Replies have been disabled for this discussion.