[Issue 2682] New: const struct initialized with struct literal recreates value on stack when used
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Sun Feb 22 05:05:05 PST 2009
http://d.puremagic.com/issues/show_bug.cgi?id=2682
Summary: const struct initialized with struct literal recreates
value on stack when used
Product: D
Version: 1.039
Platform: PC
OS/Version: Linux
Status: NEW
Keywords: wrong-code
Severity: normal
Priority: P2
Component: DMD
AssignedTo: bugzilla at digitalmars.com
ReportedBy: kamm-removethis at incasoftware.de
As the following code shows the const S s isn't really initialized with a
constant that's put into the data segment, but works more like "alias S(5) s;".
---
struct S { int i; }
const S s = S(5);
const S u = { 5 };
void foo(int num) {
printf("%p %p\n", &s, &u);
if (num > 0)
foo(num-1);
}
void main() {
foo(2);
}
---
output:
0xbfc1774c 0x80601a0
0xbfc17738 0x80601a0
0xbfc17724 0x80601a0
--
More information about the Digitalmars-d-bugs
mailing list