21
<b>$Header: /cvs/projects/SWIG/Doc/Devel/Attic/internals.html,v 1.1.2.4 2001/07/30 12:14:44 mkoeppe Exp $</b>
21
<b>$Header: /cvsroot/SWIG/Doc/Devel/internals.html,v 1.4 2003/09/23 21:38:32 cheetah Exp $</b>
24
24
(Note : This is a work in progress.)
48
48
<li><a name="i5" href="#5">5. Difference Between SWIG 1.1 and SWIG 1.3</a>
49
49
<li><a name="i6" href="#6">6. Plans for SWIG 2.0</a>
50
50
<li><a name="i7" href="#7">7. C/C++ Wrapper Support Functions</a>
51
<li><a name="i8" href="#8">8. Reserved</a>
51
<li><a name="i8" href="#8">8. Symbol Naming Guidelines for Generated C/C++ Code</a>
52
52
<li><a name="i9" href="#9">9. Reserved</a>
53
53
<li><a name="i10" href="#10">10. Guile Support</a>
54
54
<li><a name="i11" href="#11">11. Python Support</a>
921
921
<a name="8" href="#i8">
922
<h2>8. Symbol Naming Guidelines for Generated C/C++ Code</h2>
924
The C++ standard (ISO/IEC 14882:1998(E)) states:
928
17.4.3.1.2 Global names [lib.global.names]
930
1 Certain sets of names and function signatures are always reserved to the implementation:
932
* Each name that contains a double underscore (__) or begins with an underscore followed
933
by an upper case letter (2.11) is reserved to the implementation for any use.
934
* Each name that begins with an underscore is reserved to the implementation for use as
935
a name in the global namespace.165)
937
165) Such names are also reserved in namespace ::std (17.4.3.1). [back to text]
942
When generating code it is important not to generate symbols that might clash with the code being wrapped. It is tempting to flout the standard or just use a symbol which starts with a single underscore followed by a lowercase letter in order to avoid name clashes. However even these legal symbols can also clash with symbols being wrapped. The following guidelines should be used when generating code in order to meet the standard and make it highly unlikely that symbol clashes will occur:
945
For C++ code that doesn't attempt to mangle a symbol being wrapped (for example SWIG convenience functions):
947
<li> Put symbols in the <tt>Swig</tt> namespace, for example class <tt>Swig::Director</tt>. Qualify using the <tt>Swig</tt> namespace whenever the symbol is referenced, even within the <tt>Swig</tt> namespace, for example <tt>new Swig::Director()</tt> not <tt>new Director()</tt>.</li>
948
<li> Use <tt>swig_</tt> as a prefix for all member variables and member functions that are involved in an inheritance chain with wrapped classes, for example <tt>Swig::Director::swig_get_up()</tt> and <tt>bool Swig::Director::swig_up</tt>.</li>
949
<li> Alternatively class names can be prefixed with <tt>Swig</tt> in the global namespace for example <tt>template<class T> class SwigValueWrapper</tt>.</li>
953
For code compiled as C or C++ that doesn't attempt to mangle a symbol being wrapped (for example SWIG convenience functions):
955
<li> Use <tt>SWIG_</tt> as a prefix for structures for example <tt>SWIG_JavaExceptions_t</tt>.</li>
956
<li> Use <tt>SWIG_</tt> as a prefix for global functions for example <tt>SWIG_TypeRegister</tt>. </li>
957
<li> Use <tt>SWIG_</tt> as a prefix for macros for example <tt>#define SWIG_PY_INT 1</tt></li>
960
For code compiled as C or C++ that attempts to mangle a wrapped symbol:
962
<li> Use <tt>SWIGxxx</tt> or <tt>Swigxxx</tt> as a prefix where xxx is chosen which would make <tt>SWIGxxx</tt>/<tt>Swigxxx</tt> a unique symbol in the global namespace, for example <tt>class SwigDirectorFoo</tt> when wrapping <tt>class Foo</tt>. Don't use a trailing underscore for the prefix as this may generate a double underscore when wrapping a symbol which starts with a single underscore.</li>
965
In the past SWIG has generated many symbols which flout the standard especially double underscores. In fact they may not all be rooted out yet, so please fix them when you see them.
925
968
<a name="9" href="#i9">
926
969
<h2>9. Reserved</h2>