in reply to Re^8: Reference of constants and literals
in thread Reference of constants and literals
anyway I think it's a notable result of this discussion that the location of constants and literals will not be fixed at compiletime!
That's not true. Constants are allocated once at compile time.
for (1..3) { print(\1, "\n"); push @x, 'x'; # Prevent reuse of memory addresses. }
SCALAR(0x236d94) SCALAR(0x236d94) SCALAR(0x236d94)
They are tied to the opcode, and the same constant is returned every time.
PP(pp_const) { dVAR; dSP; XPUSHs(cSVOP_sv); RETURN; }
If you see otherwise, it's because you're looking at a *copy* of the constant.
Note that different instances of the same literal results in different constants.
for (1..3) { print(\1, ' ', \1, "\n"); push @x, 'x'; # Prevent reuse of memory addresses. }
SCALAR(0x236d94) SCALAR(0x183179c) SCALAR(0x236d94) SCALAR(0x183179c) SCALAR(0x236d94) SCALAR(0x183179c)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^10: Reference of constants and literals
by LanX (Saint) on Nov 24, 2008 at 17:51 UTC | |
by ikegami (Patriarch) on Nov 24, 2008 at 18:06 UTC | |
by LanX (Saint) on Nov 24, 2008 at 21:21 UTC |