Are function pointers compile time constants?
Steven Schveighoffer
schveiguy at yahoo.com
Sun Feb 20 16:24:08 PST 2011
On Sun, 20 Feb 2011 16:23:14 -0500, Nick Sabalausky <a at a.a> wrote:
> "Simon" <s.d.hammett at gmail.com> wrote in message
> news:ijrdif$1nn6$1 at digitalmars.com...
>> On 20/02/2011 14:59, d coder wrote:
>>> Greetings
>>>
>>> I tried to initialize a struct member with a function pointer, and
>>> found that DMD2 did not like it. Are not function pointers compile
>>> time constants? And why they should not be?
>>>
>>> Regards
>>> - Cherry
>>
>> No a function doesn't have an address until the .exe is loaded into
>> memory. And with Address space randomisation on 'doze there is no
>> reasonable way to make a function pointer a compile time value.
>>
>
> I didn't know Windows did that, I thought it was just certain versions of
> Unix/Linux. Do you happen to know which version of Windows was first to
> have
> it?
Probably the first one with dlls? I don't see how else you could have
dlls, because you can't just say "this function will always be at address
12345, and no other function anyone else ever compiles can take that spot".
That being said, I'm not sure why the OP's issue couldn't be solved --
clearly position independent code works (and that is statically created),
why couldn't a reference to that function also be created in a struct
initializer? Is it a limitation of the linker?
-Steve
More information about the Digitalmars-d-learn
mailing list