[Issue 3378] [tdpl] ++x should be an lvalue

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu Mar 4 04:33:06 PST 2010


http://d.puremagic.com/issues/show_bug.cgi?id=3378


Steven Schveighoffer <schveiguy at yahoo.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |schveiguy at yahoo.com


--- Comment #7 from Steven Schveighoffer <schveiguy at yahoo.com> 2010-03-04 04:33:04 PST ---
testing:

[steves at steveslaptop ~]$ cat testit.c
int x;
int * foo()
{
    return &(++x);
}
[steves at steveslaptop ~]$ gcc -c testit.c
testit.c: In function ‘foo’:
testit.c:4: error: lvalue required as unary ‘&’ operand
[steves at steveslaptop ~]$ g++ -c testit.c
[steves at steveslaptop ~]$

So, C (at least in gcc) does not consider ++x an lvalue, C++ (g++) does.

This is consistent with what Walter says.  Choosing one or the other is
arbitrarily right or wrong depending on what compatibility you wish to have.

I agree that defining ++x to be equivalent x+=1 for all types of x is bad, but
defining it that way for builtins is fine.

I don't see a huge benefit to having ++x return an lvalue.  Why can't you
rewrite bump like so?

ref int bump(ref int x) { ++x; return x;}

This should work for all types of x.

In practice, I don't think using ++x as an lvalue comes up much.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list