Binding to C - Arrays and Access Violation

Mike Parker via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Wed Feb 3 01:28:28 PST 2016


On Wednesday, 3 February 2016 at 04:19:37 UTC, jmh530 wrote:

>
> A few extra questions: 1) In other parts of the code I'm using 
> extern(System), but that doesn't work for these. Why is 
> extern(C) used for function pointers?,

extern(C) is only used with function pointers when it's needed. 
It depends entirely on how the C library was compiled.  By 
default, most compilers compile with the cdecl calling 
convention, which is what extern(C) specifies in D code. Windows 
system libraries are usually compiled to use the stdcall calling 
convention. The D equivalent is extern(Windows). extern(System) 
translates to extern(Windows) on Windows and extern(C) elsewhere. 
Function pointers passed to C code need to have the same calling 
convention as that of the library to which they are passed.

> 2) You use const(double)*, in other parts of the code I had 
> converted the C code from const char* to const(char*). Does it 
> matter where the pointer * falls?

Technically, const(char)* is a mutable pointer to const data and 
const(char*) is an immutable pointer to const data.


More information about the Digitalmars-d-learn mailing list