How to read "The lvalue-to-rvalue, array-to-pointer, and function-to-pointer standard conversionsare

Discussion in 'C++' started by Lighter, Jun 21, 2007.

  1. Lighter

    Lighter Guest

    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.
     
    Lighter, Jun 21, 2007
    #1
    1. Advertising

  2. Lighter

    James Kanze Guest

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

    On Jun 21, 4:33 am, 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 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:
    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
     
    James Kanze, Jun 21, 2007
    #2
    1. Advertising

  3. Lighter

    Lighter Guest

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

    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?
     
    Lighter, Jun 21, 2007
    #3
  4. Lighter

    Ron Natalie Guest

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

    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 (*)().
     
    Ron Natalie, Jun 21, 2007
    #4
  5. 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
     
    Victor Bazarov, Jun 21, 2007
    #5
  6. Lighter

    James Kanze Guest

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

    On Jun 21, 12:32 pm, Lighter <> wrote:
    > 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:
    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
     
    James Kanze, Jun 21, 2007
    #6
  7. Lighter

    Lighter Guest

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

    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.lang.c /browse_thread/thread/acef1d83037a6653?hl=en

    Please visit the post and give your precious tips. Thanks in advance.
     
    Lighter, Jun 21, 2007
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mark Stijnman
    Replies:
    2
    Views:
    517
    =?ISO-8859-15?Q?Juli=E1n?= Albo
    Apr 22, 2005
  2. Kavya
    Replies:
    9
    Views:
    542
    Dik T. Winter
    Oct 28, 2006
  3. usao
    Replies:
    7
    Views:
    578
    Kai-Uwe Bux
    May 22, 2008
  4. Juha Nieminen
    Replies:
    13
    Views:
    655
    Edek Pienkowski
    Aug 29, 2012
  5. Michael Lehn
    Replies:
    3
    Views:
    289
    Michael Lehn
    Oct 3, 2012
Loading...

Share This Page