Class info on interfaces

Adam D. Ruppe via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Aug 28 07:31:27 PDT 2015


On Friday, 28 August 2015 at 06:19:55 UTC, Jacob Carlborg wrote:
> Is it possible to detect at compile time if an interface is not 
> a native D interface?

Not fully, no, but you might be able to reflect into the methods 
and see what kind of linkage they have.

http://dlang.org/phobos/std_traits.html#functionLinkage

The interface itself won't necessarily be marked extern - on the 
binary level, they are all the same (I think... just a pointer to 
a list of function pointers), but if you look at the methods you 
can make a reasonably good guess.

However, you can't do anything with an interface that isn't in 
there anyway without a runtime cast, so you might want to just 
skip any compile time guesses and just go with the runtime check.

> Now when I think about it, we actually have four (!) different 
> kinds of interfaces. Native D, C++, Objective-C and COM.

aye, and since the interface is so simple at the binary level, it 
is possible to use them for other things too (I think a glib 
object in C is also binary compatible...); I'm sure this won't be 
the end of the list.


More information about the Digitalmars-d-learn mailing list