I have dll written on language X with C-ABI interface. And I want to use this C-ABI from my c++ program.
I wrote in main.cpp:
extern "C" {
struct Foo {
const char * const data;
unsigned len;
};
struct Foo f(void);
}
int main()
{
}
And got warning from compiler (visual c++/15.7.5/windows 7/32bit):
(7): warning C4190: 'f' has C-linkage specified, but returns UDT 'Foo' which is incompatible with C
(7): note: see declaration of 'Foo'
Here godbolt link: https://godbolt.org/g/ztx1kf
I read Error in C++ code linkage: warning C4190: type has C-linkage specified, but returns UDT which is incompatible with C, but in my case I have no "c++ code" at all in my POD struct.
How can I convince compiler that this is not C++ struct Foo
, but C struct Foo
?
I try to move it to separate header file (.h), but this is change nothing.
If I replace const char * const data
with const char *
warning disappear,
what I also don't understand, but I don't want to change definition of struct.