Testing if a function is defined in a module
Tyler Knott
tywebmail at mailcity.com
Tue Feb 20 22:53:46 PST 2007
Kirk McDonald wrote:
> 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
> }
>
>
Thanks for the solution. I was grappling with a similar problem myself. Would
you mind explaining why this works? I'm a bit fuzzy on IsExpression syntax.
I'm guessing it's because you can't take the type of an undeclared symbol,
making the Type invalid and the IsExpression return 0, correct?
More information about the Digitalmars-d-learn
mailing list