Testing if a function is defined in a module
Frits van Bommel
fvbommel at REMwOVExCAPSs.nl
Wed Feb 21 01:50:02 PST 2007
Tyler Knott wrote:
> Kirk McDonald wrote:
>> Carlos Smith wrote:
>>> How can i test (statically), later in the module
>>> if that function have been defined ?
>>
>> 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?
In this case it's taking the type of an expression that tries to take
the address of an undefined symbol (note the &), but other than that
your guess is right.
More information about the Digitalmars-d-learn
mailing list