Thread overview
Bug in gdc or bug in dmd?
Oct 25, 2005
David Rushby
Oct 28, 2005
Thomas Kuehne
Oct 28, 2005
David Rushby
October 25, 2005
Here's the example program:
-------------------------------------------------
const int *x;
int y = 1;

int main() {
printf("*x is %d\n", *x);
return 0;
}

static this() {
x = &y;
}
-------------------------------------------------
dmd 0.136 compiles this without an error message, and of course the output is "*x is 1".

The most recent version of gdc (0.15) issues this output when I try to compile
the example program:
-------------------------------------------------
const_lvalue.d:10: x is not an lvalue
const_lvalue.d:0: internal compiler error: Segmentation fault
Please submit a full bug report,
with preprocessed source if appropriate.
See <URL:http://gcc.gnu.org/bugs.html> for instructions.
-------------------------------------------------

Obviously gdc's internal compiler error is a bug in any case, but should it be possible to initialize 'const' variables in a module's static constructor?


October 28, 2005
David Rushby schrieb am 2005-10-25:
> Here's the example program:
> -------------------------------------------------
> const int *x;
> int y = 1;
>
> int main() {
> printf("*x is %d\n", *x);
> return 0;
> }
>
> static this() {
> x = &y;
> }
> -------------------------------------------------
> dmd 0.136 compiles this without an error message, and of course the output is "*x is 1".
>
> The most recent version of gdc (0.15) issues this output when I try to compile
> the example program:
> -------------------------------------------------
> const_lvalue.d:10: x is not an lvalue
> const_lvalue.d:0: internal compiler error: Segmentation fault
> Please submit a full bug report,
> with preprocessed source if appropriate.
> See <URL:http://gcc.gnu.org/bugs.html> for instructions.
> -------------------------------------------------
>
> Obviously gdc's internal compiler error is a bug in any case, but should it be possible to initialize 'const' variables in a module's static constructor?

- -> http://digitalmars.com/d/attribute.html

Thomas

October 28, 2005
In article <h3e833-a76.ln1@eiche.kuehne.cn>, Thomas Kuehne says...
>David Rushby schrieb am 2005-10-25:
>> Here's the example program:
>> ...
>
>- -> http://digitalmars.com/d/attribute.html

Thanks, Thomas.  Somehow I missed the second part of the 'const' documentation when I looked at it previously.