Expressions "j = ++(i | i); and j = ++(i & i); should be a lvalue error?

前端 未结 5 1647
心在旅途
心在旅途 2020-12-02 22:03

I was expecting that in my following code:

#include 
int main(){
    int i = 10; 
    int j = 10;

    j = ++(i | i);
    printf(\"%d %d\\n\         


        
5条回答
  •  温柔的废话
    2020-12-02 22:43

    C11 (n1570), § 6.5.3.1 Prefix increment and decrement operators
    The operand of the prefix increment or decrement operator shall have atomic, qualified, or unqualified real or pointer type, and shall be a modifiable lvalue.

    C11 (n1570), § 6.3.2.1 Lvalues, arrays, and function designators
    A modifiable lvalue is an lvalue that does not have array type, does not have an incomplete type, does not have a const- qualified type, and if it is a structure or union, does not have any member (including, recursively, any member or element of all contained aggregates or unions) with a const- qualified type.

    C11 (n1570), § 6.3.2.1 Lvalues, arrays, and function designators
    An lvalue is an expression (with an object type other than void) that potentially designates an object.

    C11 (n1570), § 3. Terms, definitions, and symbols
    Object: Region of data storage in the execution environment, the contents of which can represent values

    As far as I know, potentially means "capable of being but not yet in existence". But (i | i) is not capable of referencing a region a data storage in the execution environment. Therefore it is not an lvalue. This seems to be a bug in an old gcc version, fixed since. Update your compiler!

提交回复
热议问题