Namespaces clash in C

B

bnraghu23

Hi all,

In a software stack, I have an upper layer & lower layer both from
different vendors.
The lower layer (is in the form of libraries) exports some functions
say for eg: semaphore_delete(). Unfortunately, the
upper layer (is in the form of header files) also provides prototypes
for the functions whose names match exactly with the
function names exported by the lower layer. That is, the upper layer
header file has a prototype for semaphore_delete().

I want to implement this upper layer semaphore_delete()
using the lower layer semaphore_delete() function. But these 2
namespaces are clashing. I know that this problem could have
been easily solved in C++ using its namespace feature. But C
does not have this feature and hence how do I solve this problem in C.?
Has anyone come across similar kind of
problems.?

regards,
Raghunath
 
F

Flash Gordon

(e-mail address removed) wrote:

I want to implement this upper layer semaphore_delete()
using the lower layer semaphore_delete() function. But these 2
namespaces are clashing. I know that this problem could have
been easily solved in C++ using its namespace feature. But C
does not have this feature and hence how do I solve this problem in C.?
Has anyone come across similar kind of
problems.?

The only way to resolve a name clash on external symbol names (such as
exported functions) in standard C is to rename one of them. Obviously
you can only do this with something you have the source code for.

Your best bet is probably contacting the vendors involved and asking for
their assistance. Or checking to see if they have support groups or
mailing lists you can ask in.

There *may* also be system specific methods of resolving the problem,
but any such methods would be off topic here and, in my opinion, if you
don't know exactly what the repercussions will be such methods are
dangerous.

Asking here if C has a solution was reasonable, unfortunately for you
the solution is going to be outside the realms of standard C and hence
we can't help you here.
 
N

Nathan Wijnia

Hi all,

In a software stack, I have an upper layer & lower layer both from
different vendors.
The lower layer (is in the form of libraries) exports some functions
say for eg: semaphore_delete(). Unfortunately, the
upper layer (is in the form of header files) also provides prototypes
for the functions whose names match exactly with the
function names exported by the lower layer. That is, the upper layer
header file has a prototype for semaphore_delete().

I want to implement this upper layer semaphore_delete()
using the lower layer semaphore_delete() function. But these 2
namespaces are clashing. I know that this problem could have
been easily solved in C++ using its namespace feature. But C
does not have this feature and hence how do I solve this problem in C.?
Has anyone come across similar kind of
problems.?

regards,
Raghunath

You could create a layer between the software stacks and your software. A
layer then forms an abstraction of the software stack and since you're the
one who defines the interface of the layers, you can choose your own names.
So in the interface of the stack A you define a function like
A_semaphore_delete() and in the interface of stack B you have something like
B_semaphore_delete().

Regards,
Nathan
 
B

bnraghu23

Hi,

Thank you very much for this response. I'll give it a try.

regards,
Raghunath
 
D

David Resnick

Hi all,

In a software stack, I have an upper layer & lower layer both from
different vendors.
The lower layer (is in the form of libraries) exports some functions
say for eg: semaphore_delete(). Unfortunately, the
upper layer (is in the form of header files) also provides prototypes
for the functions whose names match exactly with the
function names exported by the lower layer. That is, the upper layer
header file has a prototype for semaphore_delete().

I want to implement this upper layer semaphore_delete()
using the lower layer semaphore_delete() function. But these 2
namespaces are clashing. I know that this problem could have
been easily solved in C++ using its namespace feature. But C
does not have this feature and hence how do I solve this problem in C.?
Has anyone come across similar kind of
problems.?

regards,
Raghunath

If you object to renaming your version of the function (used
in too many places?), perhaps you could use macros to achieve
your ends.

Example:

Header file:
#define semaphore_delete my_semaphore_delete
void semaphore_delete(...);

Your file that implements my_semaphore_delete
includes that header and does
#undefine semaphore_delete

It then implements my_semaphore_delete, and calls
underlying the semaphore_delete.

Ugly, perhaps, but I think it works...

-David
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top