Thread overview | ||||||
---|---|---|---|---|---|---|
|
February 04, 2013 Offset of globals in linking time. | ||||
---|---|---|---|---|
| ||||
Hi I need to initialize a global variable with a pointer to another global variable but dmd compler raises an error: uint a = 5; uint* p = &a; // error: non-constant expression & a const uint* cp = &a; // error: non-constant expression & a All C compilers support this assignation ¿whi dlang cannot? I think this is a great limitation for writing huge dependent of initial-state defined program as a virtual machine (in this case). --- Just try it with ldc, appears to work. I'm also compiling gdc for test with it. Thanks, |
February 04, 2013 Re: Offset of globals in linking time. | ||||
---|---|---|---|---|
| ||||
Posted in reply to JDavidls | On Monday, 4 February 2013 at 20:16:54 UTC, JDavidls wrote:
> I need to initialize a global variable with a pointer to another global variable but dmd compler raises an error:
That's because a is not a global variable, it is thread local.
Try:
__gshared uint a = 5;
|
February 04, 2013 Re: Offset of globals in linking time. | ||||
---|---|---|---|---|
| ||||
Posted in reply to JDavidls | On 02/04/2013 12:16 PM, JDavidls wrote:
> Hi
>
> I need to initialize a global variable with a pointer to another global
> variable but dmd compler raises an error:
>
> uint a = 5;
> uint* p = &a; // error: non-constant expression & a
> const uint* cp = &a; // error: non-constant expression & a
>
> All C compilers support this assignation ¿whi dlang cannot?
>
> I think this is a great limitation for writing huge dependent of
> initial-state defined program as a virtual machine (in this case).
>
> ---
>
> Just try it with ldc, appears to work. I'm also compiling gdc for test
> with it.
>
>
> Thanks,
Another option is to initialize in a 'static this()' block:
uint a = 5;
uint* p;
const uint* cp;
static this()
{
p = &a;
cp = &a;
}
Ali
|
February 04, 2013 Re: Offset of globals in linking time. | ||||
---|---|---|---|---|
| ||||
Posted in reply to Peter Alexander | > That's because a is not a global variable, it is thread local.
Oh, thanks
|
Copyright © 1999-2021 by the D Language Foundation