How to write a C++ header file that can be #included in a C source file when inheritance is used?
I inherited a piece of software which uses both C and C++.
A C++ header file "netlib_implementation.h" has:
(s_libReceiveSocket and s_libSendSocket are "subclasses" of s_libSocket.)
Code:
typedef struct s_libSocket t_libSocket;
struct s_libSocket {
  struct sockaddr sockAddr;
  int IP;
  int socketDescriptor;
}
typedef struct s_libReceiveSocket t_libReceiveSocket;
struct s_libReceiveSocket : s_libSocket {
   pthread_mutex_t threadMutex;
   .... ;
}
typedef struct s_libSendSocket t_libSendSocket;
struct s_libReceiveSocket : s_libSocket {
   pthread_cond_t cond;
   .... ;
}
A C++ program file "netlib.cc" has:
Code:
#include "netlib_implementation.h"
typedef t_libSocket * netHandle;
typedef t_libReceiveSocket * netRHandle;
typedef t_libSendSocket * netSHandle;
extern "C" netSHandle netOpenSendSocket( ... )
{
  t_libSendSocket *s = malloc(...);
  ...
  return s;
}
extern "C" netRHandle netOpenSReceiveSocket( ... )
{
  t_libReceiveSocket *s = malloc(...);
  ...
  return s;
}
A C program file "comm.c" calls the C++ functions:
Code:
#include "netlib.h"
netHandle comm_handle;
if (...)
  comm_handle = netOpenReceiveSocket( ... );
else
  comm_handle = netOpenSendSocket( ... );
Now the question is: How to write "netlib.h"?
(Note that I cannot #include "netlib_implementation.h" in comm.c because "netlib_implementation.h" has some inheritance stuff in it and a C compiler does not recognize such.)
Currently "netlib.h" is written as:
Code:
typedef void * netHandle;
netHandle netOpenReceiveSocket( ... );
netHandle netOpenSendSocket( ... );
Note that the return type of the two function prototypes is netHandle, not netRHandle and netShandle as in the function definition. Also, there would be two different declarations of netHandle, one as void * in "netlib.h", another as t_libSocket * in "netlib.cc". That would be quite confusing.
Is there a better way to handle this?