Translating C "static arrays" into D?

H. S. Teoh hsteoh at quickfur.ath.cx
Mon Feb 26 17:54:12 UTC 2018


What's the correct translation of the following C declarations into D?

	typedef double[1] mytype;

	void someFunc(mytype x, mytype *y, mytype **z);

	struct SomeStruct {
		mytype x;
		mytype *y;
		mytype **z;
	}

I need this to interface with an external C library.  Currently, I just
wrapped the above as-is inside an extern(C) block.  But I suspect it may
be wrong, because:

1) In C, declaring a function parameter of type double[1] is, IIRC, the
same thing as declaring it as double*.  But in D, double[1] passes one
double by value as a static array. So there may be an API mismatch here.

2) In C, declaring a *variable* or struct field as double[1] has
essentially the same semantics as D's static arrrays.  Meaning that I
cannot just change the declaration of mytype in order to get the correct
behaviour of function parameters.

3) I'm getting a segfault at runtime of some C++ code into D, that calls
the library via this C API, and I suspect it's probably due to (1).


T

-- 
Amateurs built the Ark; professionals built the Titanic.


More information about the Digitalmars-d mailing list