ho***@mail.ru (Alexander Gorshenev) wrote in message news:<ab*************************@posting.google.c om>...
I am looking for an elegant solution for the following problem:
I have two projects for which I have to create a kind of bridge
or translator between. For each of the projects there exist a set of headers
included by practicaly all of the member .c files.
For my bridge I would be using all those "main" headers from
both of the projects included together.
But unfortunately, due to historical reasons, those headers
conflict in many points. The conflicts are as:
project A: enum {Monday, Friday, Sunday};
project B: enum {Friday, Sunday, Sausidge, HotDog };
I have no rights to modify the headers because those
constitute the public interfaces.
And it is required for me to make minimal changes to existing code.
So what would smart guys advise?
I may be excoriated for making a C++ suggestion in c.l.c, but what the
heck. *If* C++ is an option for your bridge program (and given your
description of the system, it may well be), the use of namespaces can
separate the (non-preprocessing) names in the two headers fairly well.
And just use C++ as a "better C" (the "better" part being the
existence of namespaces in this case).
Include the two header files inside namespace declarations:
namespace ProjectA {
#include <headera.h>
}
namespace ProjectB {
#include <headerb.h>
}
Then you can reference things like:
if (a == ProjectA::Monday)
/* do something */
Again, this won't fix any of your #defines. And it may well lead to
linkage problems with function calls or other external (eg. global)
definition in the two headers (but you'd have those anyway). But for
things like structures and types, namespaces can take care of a lot.