C++ Interfacing:'static' array function parameter contradiction
ParticlePeter via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Fri Apr 28 11:07:49 PDT 2017
On Friday, 28 April 2017 at 17:57:34 UTC, Ali Çehreli wrote:
> 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
Interesting, your example corresponds to my third case, the
linker error. I am on Window, building an x64 App, afaik in that
case the MS Visual Studio linker is used instead of optilink.
Will add your findings to the bug report.
More information about the Digitalmars-d-learn
mailing list