[OpenIndiana-discuss] weird C++ problem

James Carlson carlsonj at workingcode.com
Mon Apr 1 20:53:24 UTC 2013


On 04/01/13 15:51, Apostolos Syropoulos wrote:
>     // unfortunately, the kpathsea headers are not C++-ready,
>     // so we have to wrap it with some ugly code
>     //namespace KPS {
>         extern "C" {
>             #include <kpathsea/kpathsea.h>

Wow.  I read that as insult added to injury.  :-/

I'll assume that you don't want to discuss the problem with the original
author.  (That's really the right thing to do, but I agree that it's
sort of a non-answer since you've said that "all" you want to do is
compile it, and sending a bug report upstream might not achieve that goal.)

Given that you're already in a world of terrible hacks, you might be
able to get around some of this wackiness by pre-including the includes
that are needed internally, so that the nested includes do nothing.
Something like this:

#include <string.h>
namespace KPS {
  extern "C" {
     #include <kpathsea/kpathsea.h>
  }
}

Because /usr/include/string.h has the normal #ifndef/#define wrapper on
it, changing the code as I describe above will cause this header file to
be included once in the proper context.  The second inclusion (buried
somewhere inside the expansion of kpathsea.h) will get dummied out by
the standard wrapper, and thus won't fall apart due to the weird KPS
context shifting going on here.

It's likely that this isn't the only header file that is affected, and
you may need a list of them.

Really, the right answer is to teach kpathsea.h how to be parsed by a
modern C++ compiler, and not to try to kludge around it in some other
random application with a brutal namespace hack.  It's 2013, right?

-- 
James Carlson         42.703N 71.076W         <carlsonj at workingcode.com>



More information about the OpenIndiana-discuss mailing list