extern(C) function declarations and extra keywords.

ponce contact at gam3sfrommars.fr
Sat Dec 28 13:57:06 PST 2013


> Since the C functions can't access anything from D code save 
> for what is passed through as parameters, can it be called pure?

Probably not since it might not be pure and eg. mutate global 
variables.

> Does purity do anything in terms of speed/safety here?
A pure function is expected to give the same result given the 
same parameters.
Similar calls to a pure function (same parameters) can be 
optimized out by the compiler.

> 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?

No speed or safety benefit, but it allows to call these C 
functions in functions marked nothrow themselves. As a rule of 
thumb you can put nothrow systematically when binding C code.

> And likewise as with the pure aspect, does the compiler know 
> how to distinguish C and D and make it inherently nothrow?

No.

> 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?

No.


More information about the Digitalmars-d-learn mailing list