home *** CD-ROM | disk | FTP | other *** search
-
-
- OS/2 DDE4MNCH (munch)
- ---------------------
-
- This document describes how to use the DDE4MNCH.EXE tool ( otherwise
- known as "munch" ) for the OS/2 IBM C++ compiler. The munch utility
- is used to map compiler generated template names to user template
- names in C++ programs that use C++ templates. This mapping is
- necessary because the compiler generates unique names for all
- template function instances in all .objs . It does this because it
- does not know when it is compiling 'a.c' if there is a user defined
- template function in 'b.c'. If 'b.c' does contain a user template
- function then it should be used instead of the compiler generated
- one. To resolve the name mappings it is necessary for munch to read
- a list of .objs and to check each compiler generated template
- function against all of the user defined functions. If a match is not
- found then the mapping of the compiler name to the user name is
- performed.
-
- An example of using munch:
-
- File: stacktpl.h
-
- | template<class T>
- | class stack
- | {
- | private:
- | T *v, *p;
- | int sz;
- |
- | public:
- | stack( int size );
- | ~stack();
- | void push( T );
- | T pop();
- | };
-
- File: stacktpl.c
-
- | template<class T> stack<T>::stack( int size ) { v = p = new T[sz=size]; }
- | template<class T> stack<T>::~stack() { delete [] v; }
- | template<class T> void stack<T>::push( T a ) { *p++ = a; }
- | template<class T> T stack<T>::pop() { return *--p; }
-
- File: main.c
-
- | #include <stdio.h>
- | #include "stacktpl.h"
- | #include "stacktpl.c"
- |
- | void setup();
- |
- | void main()
- | {
- | stack<int> intStack(2);
- |
- | intStack.push( 42 );
- | setup();
- | printf( "%d !\n", intStack.pop() );
- | }
-
- File: part1.c
-
- | #include <stdio.h>
- | #include "stacktpl.h"
- | #include "stacktpl.c"
- |
- | void setup()
- | {
- | stack<char *> charpStack(4);
- |
- | charpStack.push( "is " );
- | charpStack.push( "answer " );
- | charpStack.push( "The " );
- |
- | printf( "%s", charpStack.pop() );
- | printf( "%s", charpStack.pop() );
- | printf( "%s", charpStack.pop() );
- | }
-
-
- The compile command for the example is:
-
- icpp -fd -c main.c part1.c
-
- The munch command for the example is:
-
- dde4mnch main.obj part1.obj
-
- ( munch currently produces an object called os2temp.obj )
-
- The link command for the example is:
-
- icpp main.obj part1.obj os2temp.obj
-
-
-