home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Professional Developers Kit 1992 November / Disc01 / Disc01.mdf / cppbeta / doc1 / dde4mnch.do_ / DDE4MNCH.DOC
Encoding:
Text File  |  1992-09-29  |  3.0 KB  |  98 lines

  1.  
  2.  
  3.                           OS/2 DDE4MNCH (munch)
  4.                           ---------------------
  5.  
  6.    This document describes how to use the DDE4MNCH.EXE tool ( otherwise
  7.    known as "munch" ) for the OS/2 IBM C++ compiler. The munch utility
  8.    is used to map compiler generated template names to user template
  9.    names in C++ programs that use C++ templates. This mapping is
  10.    necessary because the compiler generates unique names for all
  11.    template function instances in all .objs . It does this because it
  12.    does not know when it is compiling 'a.c' if there is a user defined
  13.    template function in 'b.c'. If 'b.c' does contain a user template
  14.    function then it should be used instead of the compiler generated
  15.    one. To resolve the name mappings it is necessary for munch to read
  16.    a list of .objs and to check each compiler generated template
  17.    function against all of the user defined functions. If a match is not
  18.    found then the mapping of the compiler name to the user name is
  19.    performed.
  20.  
  21.    An example of using munch:
  22.  
  23.       File: stacktpl.h
  24.  
  25.         |   template<class T>
  26.         |   class stack
  27.         |   {
  28.         |      private:
  29.         |         T  *v, *p;
  30.         |         int sz;
  31.         |
  32.         |      public:
  33.         |                stack( int size );
  34.         |                ~stack();
  35.         |          void  push( T );
  36.         |          T     pop();
  37.         |   };
  38.  
  39.       File: stacktpl.c
  40.  
  41.         |   template<class T> stack<T>::stack( int size ) { v = p = new T[sz=size]; }
  42.         |   template<class T> stack<T>::~stack()          { delete [] v;            }
  43.         |   template<class T> void stack<T>::push( T a )  { *p++ = a;               }
  44.         |   template<class T> T stack<T>::pop()           { return *--p;            }
  45.  
  46.       File: main.c
  47.  
  48.         |   #include <stdio.h>
  49.         |   #include "stacktpl.h"
  50.         |   #include "stacktpl.c"
  51.         |
  52.         |   void setup();
  53.         |
  54.         |   void main()
  55.         |   {
  56.         |      stack<int> intStack(2);
  57.         |
  58.         |      intStack.push( 42 );
  59.         |      setup();
  60.         |      printf( "%d !\n", intStack.pop() );
  61.         |   }
  62.  
  63.       File: part1.c
  64.  
  65.         |   #include <stdio.h>
  66.         |   #include "stacktpl.h"
  67.         |   #include "stacktpl.c"
  68.         |
  69.         |   void setup()
  70.         |   {
  71.         |      stack<char *> charpStack(4);
  72.         |
  73.         |      charpStack.push( "is "     );
  74.         |      charpStack.push( "answer " );
  75.         |      charpStack.push( "The "    );
  76.         |
  77.         |      printf( "%s",   charpStack.pop() );
  78.         |      printf( "%s",   charpStack.pop() );
  79.         |      printf( "%s",   charpStack.pop() );
  80.         |   }
  81.  
  82.  
  83.    The compile command for the example is:
  84.  
  85.        icpp -fd -c main.c part1.c
  86.  
  87.    The munch command for the example is:
  88.  
  89.        dde4mnch main.obj part1.obj
  90.  
  91.        ( munch currently produces an object called os2temp.obj )
  92.  
  93.    The link command for the example is:
  94.  
  95.        icpp main.obj part1.obj os2temp.obj
  96.  
  97.  
  98.