Testing if a function is defined in a module
Kirk McDonald
kirklin.mcdonald at gmail.com
Tue Feb 20 20:14:29 PST 2007
Carlos Smith wrote:
> Hi!
>
> say i have defined a function (or i dont):
>
> int YYUSERINIT( )
> {
> ...
> }
>
>
> How can i test (statically), later in the module
> if that function have been defined ?
>
> if yes, code using the function will
> be compiled.
>
> Thanks
>
>
There are a few ways of phrasing this, but here's one:
static if (is(typeof(&YYUSERINIT))) {
// Do stuff with the function
}
However, I can't help but wonder what situation you're in where you need
to check this directly. I'm just guessing, here, but you'd probably be
better off using a version flag:
version (WithTheFunction) int YYUSERINIT() {}
// Later...
version (WithTheFunction) {
// Use the function
}
// ...
--
Kirk McDonald
http://kirkmcdonald.blogspot.com
Pyd: Connecting D and Python
http://pyd.dsource.org
More information about the Digitalmars-d-learn
mailing list