Interfacing to const T& or const T* C++ code

bearophile via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sun Jun 1 02:18:49 PDT 2014


Atila Neves:

> D:
>      struct Foo { int i; int j; }
>      extern(C++) void useFoo(ref const(Foo) foo);
>
> C++:
>      struct Foo { int i; int j; };
>      void useFoo(const Foo& foo) { ... }

This doesn't look very safe because D const is transitive, unlike 
the C++ const. So in the C++ code you can mutate inner data 
inside foo and the D code will assume such data is not changed.

Bye,
bearophile


More information about the Digitalmars-d-learn mailing list