C++ Interfacing:'static' array function parameter contradiction

Ali Çehreli via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Apr 28 10:57:34 PDT 2017


On 04/28/2017 08:56 AM, ParticlePeter wrote:
 > C++ Function:
 > bool cppFunc( float[3] color );
 >
 > D binding:
 > extern(C++) bool cppFunc( float[3] color );
 >
 > Using with:
 > float[3] my_color;
 > cppFunc( my_color );
 >
 > -> Error: Internal Compiler Error: unable to pass static array to

That part is a bug at least in the compiler message. Is it really an 
internal ctompiler error? Doesn't look like it: the compiler is talking 
to us happily. :)

My simple test works for me:

// deneme.cpp
float cppFunc(float color[3]) {
     return color[0] + color[1] + color[2];
}

$ g++ -c deneme.cpp -o deneme_cpp.o

// deneme.d
extern(C++) float cppFunc(float * color);

void main() {
     float[3] my_color = [ 1.5, 2.5, 3.5 ] ;
     assert(cppFunc(my_color.ptr) == 7.5);
}

$ dmd deneme_cpp.o deneme.d -of=deneme

Builds and runs fine... on Linux... I don't know whether that's significant.

Ali



More information about the Digitalmars-d-learn mailing list