OSLib Namespace for C++

Tony van der Hoff OSLib at mk-net.demon.co.uk
Wed May 31 09:19:11 BST 2000


On Tue, 30 May 2000, at 19:45:17, Alexander Thoukydides
<alex at thouky.co.uk> wrote on the subject "OSLib Namespace for C++":

>One solution to some of the problems raised by using a namespace for OSLib would 
>be same as that used for standard C library files within the standard C++ 
>library, i.e. to have two sets of header files.
>
<snip>

Yes, that was another thought. However, I see no great advantage of
doing that over defining NAMESPACE_OSLIB either in the source or on the
command line.

>However, for OSLib it is necessary to specify "C" linkage (as in the above 
>exampe), thereby preventing the symbol names from being affected by the 
>namespace. This means that only type definitions will be protected by the 
>namespace - OSLib defines constants as macros so they aren't affected by 
>namespaces, and the raw names of SWI veneers still need to be unique to prevent 
>clashes during linking.
>
Unless I'm misunderstanding you, my tests suggest that things are not
quite that bad.

Using G++, my experimental OSLib-with-namespace build faults OSLib calls
without either the "using" directive or the OSLib:: qualifier when
NAMESPACE_OSLIB is defined, so there is some compile-time protection.

I can define a local os_write0() which calls OSLib::os_write0(); this
compiles, links, and runs correctly. Looking at the AOF, the global has
been name-mangled, whereas the external with "C" linkage has not.  

Obviously, another library with "C" linkage couldn't use the same
function names; and I guess that's what you're saying.

So, whilst not ideal, the namespace adds some improvement over what is
there, and in any case, there are enough type definitions to make
protecting them worthwhile. Shame about the macros though :-(

>My personal feeling is that adding a namespace to OSLib doesn't offer sufficient 
>advantages to outweigh the additional complications.
>
Thanks for that, Alex. However, I think, using my proposed
implementation, the extra complication is minimal, and as namespace
usage becomes more common, some benefits can be derived by those
choosing to use it. Those that choose not to use it will see no
difference.

Hmm, I wonder how difficult it would be to develop an OSLib++ variant...

-- 
Tony van der Hoff         |  Mailto:tony at mk-net.demon.co.uk
                          |  Mailto:avanderhoff at iee.org
Buckinghamshire, England  |  http:www.mk-net.demon.co.uk



More information about the oslib-user mailing list