If you have a C file, compiled with a C compiler and have defined behavior for C but not C++, can you link it with a C++ file and not have undefined behavior?
in blah.c (the file compiled as C)
struct x {
int blah;
char buf[];
};
extern char * get_buf(struct x * base);
extern struct x * make_struct(int blah, int size);
blah_if.h
extern "C"
{
struct x;
char * get_buf(struct x * base);
struct x * make_struct(int blah, int size);
}
some_random.cpp (Compiled with a C++ compiler)
#include "blah_if.h"
...
x * data=make_struct(7, 12);
std::strcpy(get_buf(data), "hello");
Is using the defined behavior in C's flexible array member in a file compiled with a C compiler, defined behavior when used by a file compiled as C++ and linked with the object from the C compiler?
Note that because a C compiler is used and struct x
is opaque, this is different than:
Does extern C with C++ avoid undefined behavior that is legal in C but not C++?