Rvalue references

From the C++11 FAQ, section on rvalue references, about a simple incrementation function incr:

If that incr(0) were allowed either some temporary that nobody ever saw would be incremented or - far worse - the value of 0 would become 1. The latter sounds silly, but there was actually a bug like that in early Fortran compilers that set aside a memory location to hold the value 0.

That actually made me think about that nifty one-liner:

perl -wE 'Internals::SvREADONLY(${\undef},0);undef=42;say undef'

4 Comments

Rvalue references are more awesome than most people realize.

As for your one-liner, I honestly think that that should be disallowed, at least for "immortals".


$ perl -wE 'Internals::SvREADONLY(${\undef},0);undef=42;say undef; undef $^O; say $^O'
42
Use of uninitialized value $^O in say at -e line 1.

@Burak:

The code sets the undef variable (that secretly exists behind the undef keyword), it will not change any other undefined value.

Right... I thought it was also creating a glob at the same time (which I'd expect to override undef()).

Leave a comment

About Rafaël Garcia-Suarez

user-pic I can haz Perl.