On Sun, 20 Feb 2011 16:23:14 -0500, Nick Sabalausky <[email protected]> wrote:
"Simon" <[email protected]> wrote in message
news:[email protected]...
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