Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to deal with daft header files

Tags:

c++

include

I'm trying to use a third party SDK in some C++ code. While the SDK and headers are technically compatible with C++, it's really just a lump of nasty C.

In particular the main header files has many hundreds of #defines of which these are the worst.

#define     C  0       //Celsius
#define     F  1       //Fahrenheit
#define     R  2       // Rankine
#define     K  3       // Kelvin

Now, you can imagine what nice error messages I get when trying to use boost libraries that have things like this in them:

template< typename F > struct template_arity;

A few tactical #undefs could fix things, but it still feels like a ticking bomb. I could alternatively rewrite large parts of the third-party header, or maybe just try and isolate the sections I really need.

Is there any better solution to this problem?

like image 903
Roddy Avatar asked Dec 17 '22 19:12

Roddy


2 Answers

What about only incuding the offnding files in a single .cpp file, and then just expose the functionality you need through a separate header?

like image 167
jalf Avatar answered Dec 27 '22 17:12

jalf


Have the original author rewrite it for you?

Seriously, this looks like a case of very poor design. I'd rewrite the macros, perhaps as enums.

like image 30
Fred Foo Avatar answered Dec 27 '22 18:12

Fred Foo