generalized lvalues
Nathan Sidwell
nathan@codesourcery.com
Fri Nov 19 13:10:00 GMT 2004
Ziemowit Laski wrote:
> The "cleanest" syntactic approach we could come up with so far is
>
> __builtin_objc_gc_strong(ptr) = object;
>
> which I suppose we can live with, though the lhs doesn't look too
> lvaluish this way... :-(
It looks more lvaluish than '(cast)ptr = object'. Functions can
return references (in C++), so one could actually write such a function.
The same is not true of the cast notation.
void *&__builtin_objc_gc_strong(void *&p) {return p;}
Do you need a solution that works in both C and C++?
If you're adding language extensions, you should choose one that is the
smallest possible extension (ideally, it would be 'not-an-extension').
The cast-as-lvalue idea fails for C++, as Joe Buck has pointed out, and
it fails for C as it makes a whole swathe of ill-formed uses now well-formed,
but with non-intuitive semantics. For instance does '(short)int_var = something'
write only the 'short' bits of int_var, or the whole thing? What
does '(int)short_var = something' mean? What does '&(short)int_var' give you?
Is it endian-dependent? Sure, meanings could be defined, but ISTM that
there's a whole rat's nest of strange corner conditions ready trip up
programmers and compilers.
nathan
--
Nathan Sidwell :: http://www.codesourcery.com :: CodeSourcery LLC
nathan@codesourcery.com :: http://www.planetfall.pwp.blueyonder.co.uk
More information about the Gcc
mailing list