[Libevent-users] evdns C++ incompatibility

Nick Mathewson nickm at freehaven.net
Tue Oct 2 15:36:30 EDT 2007


On Tue, Oct 02, 2007 at 03:18:15PM -0400, Roger Clark wrote:
> Most of the header is already surrounded with extern "C", but not the
> offending part. Just wanted to give someone a heads up.

I just changed it, but it doesn't do any good.  My understanding is
that 'extern "C"' is only for linkage, and it doesn't keep the
compiler from interpreting "class" as a C++ keyword.

For example, the following C++ is invalid:
   extern "C" {
     struct s { int class; };
   }

So, it looks like we've got a few options here:
  1) Rename the field and break old code that uses it.  I think I may
     be the only user of this interface, so this wouldn't necessarily
     be a tragedy... but if there are others, we might cause them some
     grief.

  2) Do some malarkey like

struct evdns_server_request {
   /* ... */
#ifdef __cplusplus
    int dns_question_class;
#else
    int class;
#define dns_question_class class
#endif
  /* ... */
};

     so that we don't break existing C code that uses the field, but
     we start building under C++, and everybody can start migrating to
     the question_class field name.

  3) Do something like

struct evdns_server_request {
   /* ... */
#ifdef __cplusplus
    int dns_question_class;
#else
    int class;
#endif
  /* ... */
};
     so that we break absolutely no old code, and C++ starts working.
     Of course, this would give the field a different name in C than
     in C++, and that's not so great.

yrs,
-- 
Nick Mathewson
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 652 bytes
Desc: not available
Url : http://monkeymail.org/archives/libevent-users/attachments/20071002/013f067a/attachment.bin


More information about the Libevent-users mailing list