Are function pointers compile time constants?

Dan Olson zans.is.for.cans at yahoo.com
Sat Feb 26 09:40:01 PST 2011


d coder <dlang.coder at gmail.com> writes:

> 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

I just want to point out that this *should* be doable in D.  At compile
time the function's address in the object code is a placeholder that the
linker or loader will fixup based on the function symbol.  This is what
linkers do!  And if an function ptr is used, the function can still be
inlined; just need to keep around the real function reference through
the pointer.

Dan


More information about the Digitalmars-d-learn mailing list