extern(C) function declarations and extra keywords.

Jeremy DeHaan dehaan.jeremiah at gmail.com
Sat Dec 28 13:47:17 PST 2013


I was thinking of adding some keywords like final, pure, and 
nothrow in to my library to improve various things where 
improvements could be made. As I was thinking about this, I 
wondered about my extern(C) function declarations and how 
keywords could improve those as well.

Since the C functions can't access anything from D code save for 
what is passed through as parameters, can it be called pure? And 
if so, does the compiler know how to distinguish C and D in this 
instance and make it inherently pure? Does purity do anything in 
terms of speed/safety here?

I noticed that in Deimos and Derelict that most(if not all) C 
function declarations are marked as nothrow. What are the 
speed/safety benefits of including this? And likewise as with the 
pure aspect, does the compiler know how to distinguish C and D 
and make it inherently nothrow?

C's name mangling doesn't allow function overloading, but as far 
as I know you can overload extern(C) functions in D. Does adding 
final help with speed improvements in the D side of things if 
added to an extern(C) function declaration?

Thanks much!


More information about the Digitalmars-d-learn mailing list