lvalues [was: curly-brace-aphobic?]
Steven D. Majewski
sdm7g at virginia.edu
Tue Jan 30 17:37:04 EST 2001
More information about the Python-list mailing list
Tue Jan 30 17:37:04 EST 2001
- Previous message (by thread): curly-brace-aphobic?
- Next message (by thread): curly-brace-aphobic?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
I used to do that in VAX C all the time (i.e. functions returning lvalues): a = pop(); b = pop(); push() = a + b ; Then I think ANSI C disallowed it. Then I think gcc put it back as an extension. Don't know for sure -- since then, portability concerns have taught me to code more conservatively. -- Steve M. On Tue, 30 Jan 2001, Rainer Deyke wrote: > "Quinn Dunkan" <quinn at groat.ugcs.caltech.edu> wrote in message > news:slrn97cu0u.eti.quinn at groat.ugcs.caltech.edu... > > If C++ allows 'f(x) = y;', then C++ is truly weird. What is *that* > supposed > > to mean? 'f(x)' returns a value, and assigning to a value makes no sense. > > You assign to variables, not values. I could understand '*(f(x)) = y;', > but > > the only way I can see to get 'f(x) = y;' to do what you want is to have > 'f' > > return an lvalue. Icon does stuff like that, but it has an excuse: it's > icon. > > Just out of curiosity, what is the type of the C++ 'f' function above (and > > don't say "cpp macro" :) ? It's likely C++'s idea of assignment is one > I'm > > not familiar with. > > 'f' here is a function that returns a reference: > > int& f(int); > > This is particularily useful when implementing 'operator[]': > > struct array { > int data[5]; > int& operator[](int n) { return data[n]; } > }; > > array a; > a[0] = 5; > a.operator[](0) = 5; // This statement is equivalent to the one above it. > >
- Previous message (by thread): curly-brace-aphobic?
- Next message (by thread): curly-brace-aphobic?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list