Namespaces clash in C

Discussion in 'C Programming' started by bnraghu23@yahoo.com, Oct 2, 2005.

  1. Guest

    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
    , Oct 2, 2005
    #1
    1. Advertising

  2. Flash Gordon Guest

    wrote:

    <snip>

    > 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.
    --
    Flash Gordon
    Living in interesting times.
    Although my email address says spam, it is real and I read it.
    Flash Gordon, Oct 2, 2005
    #2
    1. Advertising

  3. <> schreef in bericht
    news:...
    > 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
    Nathan Wijnia, Oct 2, 2005
    #3
  4. Guest

    Hi,

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

    regards,
    Raghunath

    Nathan Wijnia wrote:
    > <> schreef in bericht
    > news:...
    > > 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
    , Oct 5, 2005
    #4
  5. wrote:
    > 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
    David Resnick, Oct 5, 2005
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?RnJhbmtfMDAwMDE=?=

    Controls.Add clash with Inner.Html?

    =?Utf-8?B?RnJhbmtfMDAwMDE=?=, Jul 14, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    2,200
    =?Utf-8?B?c29jaWV0b3BpYS5uZXQ=?=
    Jul 14, 2005
  2. Jacob

    class name clash

    Jacob, Feb 6, 2004, in forum: Java
    Replies:
    14
    Views:
    812
    Larry Barowski
    Feb 10, 2004
  3. Jan Engelhardt
    Replies:
    3
    Views:
    358
    Mike Wahler
    Aug 20, 2003
  4. Martin Bless

    Q: distutils - name clash protection?

    Martin Bless, Jul 26, 2004, in forum: Python
    Replies:
    3
    Views:
    266
    Calvin Spealman
    Aug 2, 2004
  5. Olivier Vierlinck

    built-in function- module name clash

    Olivier Vierlinck, Sep 6, 2004, in forum: Python
    Replies:
    2
    Views:
    293
    Alex Martelli
    Sep 6, 2004
Loading...

Share This Page