473,387 Members | 1,899 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

conflicting headers

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?
Nov 14 '05 #1
4 1963

"Alexander Gorshenev" <ho***@mail.ru> wrote in message

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.

You've hit the typedef BOOL problem. Inexperienced programmers often define
identifiers like BOOL to make their code more readable, which it does, until
someone wants to include a function from another source that typedefs
"Bool".

What you want to do is create two "interface" files that sit on top of your
two chunks of legacy C code. Don't allow the legacy code to be called except
through the interfaces. In some cases the interface can be simply a call to
a legacy function. In other cases, for instance with the enumerated types,
you will have to translate the interface you provide into a legacy enum. You
can also probably neaten up the interface a little bit, to make the exercise
more worthwhile.
Nov 14 '05 #2
ho***@mail.ru (Alexander Gorshenev) wrote:
# 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 };

#define Monday A_Monday
#define Friday A_Friday
#define Sunday A_Sunday
#include "project A.h"
#undef Monday
#undef Friday
#undef Sunday

#define Friday B_Friday
#define Sunday B_Sunday
#define Sausidge B_Sausidge
#define HotDog B_HotDog
#include "project B.h"
#undef Friday
#undef Sunday
#undef Sausidge
#undef HotDog

--
SM Ryan http://www.rawbw.com/~wyrmwif/
JUSTICE!
Justice is dead.
Nov 14 '05 #3
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.
Nov 14 '05 #4
SM Ryan <wy*****@tango-sierra-oscar-foxtrot-tango.fake.org> wrote in message
# 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 };

#define Monday A_Monday
#define Friday A_Friday
#define Sunday A_Sunday
#include "project A.h"
#undef Monday
#undef Friday
#undef Sunday

#define Friday B_Friday
#define Sunday B_Sunday
#define Sausidge B_Sausidge
#define HotDog B_HotDog
#include "project B.h"
#undef Friday
#undef Sunday
#undef Sausidge
#undef HotDog


Thanks,

of all three given variants (stub headers, namespaces, re#defines)
this one looks better for me. So I am going with it unless there
will be any more troubles.

horsh
Nov 14 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: frasfan | last post by:
Hi, I am having a problem with the validator controls in VB.net conflicting with the javascript I am using to confirm whether or not the user wants to submit the page. Here is the situation: I...
1
by: Julia Briggs | last post by:
Hello, I have these two scripts, where the first one is being canceled out by the second, they work independently, but not together (they are a auto-tab and form box character counter script) --...
10
by: Minti | last post by:
I tried the following code on Borland C++ complier and Microsoft VC7.0 both seem to give conflicting results void foo(const int& x) { std::cout << "In const foo\n"; } void foo(int& x) ...
2
by: humble04 | last post by:
Hi, I am compiling a collection of C++ code. Most of them are using the new format #include <iostream>. I think all of them because I failed at finding out which header file uses the old format ...
6
by: user | last post by:
Hi, I got this error and donno know how to fix it: In file included from ../except.h:53, from group.c:22: .../portspecs.h:81: error: conflicting types for `const double __infinity'...
7
by: Thiru | last post by:
I am writing an application that interacts with Oracle and Teradata. In order to create the executable, I need to link various Oracle and Teradata libraries. I found out that when I link the...
8
by: Lathe_Biosas | last post by:
Hi While compiling my application that needs "windows.h" there are some typedef redefinition errors redefinition at winnt.h( line 207) typedef void *HANDLE redefinition at windef.h( line...
1
by: helraizer1 | last post by:
Hi folks, I have an image based shoutbox which I am currently implementing emoticons onto. I have a way now for the emoticons to appear where the :D or =) etc. is on the image, but for some reason...
12
by: Michael.Z | last post by:
Anyone who can help: Given a Table.h file I am writing a Table.c file. I keep getting the compile error: previous declaration of Table was here / conflicting types for I think the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.