Is it legal to forward-declare a struct as a C-struct
// api.h
#ifdef __cplusplus
extern "C" {
#endif
typedef struct handle_tag handle_t;
handle_t *construct();
void destruct(handle_t *h);
void func(handle_t *h);
#ifdef __cplusplus
}
#endif
and subsequently define it as a C++-struct, i.e. as a non-POD type?
// api.cpp
struct handle_tag {
void func();
std::string member;
};
void func(handle_t *h) {
h->func();
}
The general intention is to get via a C interface an externally accessible opaque type handle_t which is internally implemented as an C++ data type.
handle_t*looks extremely unnatural to me, and I would probably use plainhandle_tconstantly and unconsciously and then be annoyed when it doesn't compile. Compare theHANDLEand similar types in the Windows API.