home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / lang / cplus / 19964 < prev    next >
Encoding:
Internet Message Format  |  1993-01-28  |  6.4 KB

  1. Path: sparky!uunet!tcsi.com!iat.holonet.net!news.cerf.net!usc!rpi!batcomputer!munnari.oz.au!metro!otc!swdev!grahamd
  2. From: grahamd@swdev.research.otca.oz.au (Graham Dumpleton)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Was: Template Use <sigh>
  5. Message-ID: <7203@otc.otca.oz>
  6. Date: 27 Jan 93 00:06:54 GMT
  7. References: <1jp50dINNk34@rs6000.bham.ac.uk> <81348@hydra.gatech.EDU> <C1A4n9.1Iz@apollo.hp.com>
  8. Sender: news@otc.otca.oz
  9. Organization: Technical Development Group, OTC Australia
  10. Lines: 141
  11.  
  12.  
  13.  > >->There are unresolved symbols, yet the instantiator doesn't do anything
  14.  > >->about them.
  15.  > >->
  16.  > >->What am I doing wrong??? Any ideas?
  17.  > >->
  18.  > >->Guy. 
  19.  > >
  20.  > >Put ALL of your template code in header (.h) files.  Do not put template
  21.  > >code (member functions) in .c files.  In other words, get rid of
  22.  > >loopuptable.c (or whatever you called it).
  23.  > >
  24.  > >This worked for me.
  25.  > 
  26.  > It may work, but it is unnecessary with cfront 3.0.X.  We have several
  27.  > very large systems under development here that utilize templates with
  28.  > separate header and implementation files.
  29.  > 
  30.  > The cfront auto instantiation system won't bother attempting template
  31.  > instantiation if it cannot find its type map, which is the file
  32.  > ptrepository/defmap by default.
  33.  
  34. As well as starting the template instatiation mechanism when there is a non
  35. empty defmap file in the first or default repository directory, the AT&T
  36. compiler will also start the template instantiation mechanism in a number
  37. of other situations also. The list of cases that we have found, including
  38. that that you mention, is:
  39.  
  40.   1) The default repository directory is being used or only one repository
  41.   directory is explicitly defined on the command line, and there is a non
  42.   empty defmap file in the repository directory.
  43.  
  44.   2) A single repository is being used and the directory doesn't contain a
  45.   non empty defmap file but does contain a user provided nmap file.
  46.  
  47.   3) Multiple repository directories are defined explicitly on the command
  48.   line and the first directory doesn't contain a non empty defmap file or
  49.   user defined nmap files but a subsequent repository directory does.
  50.  
  51. I should point out that the HP C++ compiler version 3.0 (port of AT&T
  52. 3.0.1) doesn't start the instantiation mechanism in situations 2 and 3.
  53. Someone in HP whom I had mail contact with does know about this now, however
  54. whether they are changing their compiler to behave in the same way as the
  55. AT&T compiler I do not know. The last I heard was that they were expecting
  56. us to lodge a defect report, however since we don't actually have HP
  57. machines we haven't had a reason to do that.
  58.  
  59.  > If one builds a library archive
  60.  > containing unresolved template references in directory "A", then one
  61.  > attempts to link against that archive in directory "B", template
  62.  > instantiation will fail unless directory "B" happens to contain a type
  63.  > map that allows cfront to locate all the types necessary to perform
  64.  > the instantiation.
  65.  
  66. Due to situation 1 above.
  67.  
  68.  > If the user in directory "B" has the necessary
  69.  > write permissions for the repository in directory "A", s/he can use
  70.  > the -ptr option to the compiler to specify that repository instead of
  71.  > the default, and the link should then work.  If repository "A" is not
  72.  > writable, the user can specify a writable directory as the first
  73.  > repository on the command line, followed by another -ptr specifying
  74.  > "A" as a read-only repository:
  75.  > 
  76.  >     CC ... -ptr my_ptrep -ptr A/ptrepository ...
  77.  
  78. Actually
  79.  
  80.      CC ... -ptrmy_ptrep -ptrA/ptrepository ...
  81.  
  82. I don't think it will accept a space after the -ptr.
  83.  
  84. Also this will not work with HP C++ 3.0, as it relies on situation 3 above.
  85. What you can do is to create a dummy defmap file in the first repository
  86. directory which contains something like
  87.  
  88.   @dec ____DUMMY____
  89.   <____DUMMY____>
  90.  
  91. and it will then work.
  92.  
  93.  > All of this is well documented by the cfront release notes.
  94.  
  95. I would say that the exact situations in which the template instantiation
  96. mechanism is started isn't actually well described. I could be wrong but
  97. the only explicit mention I can find about this is:
  98.  
  99.   Selecting Readings page 8-14
  100.  
  101.     There is no easy way to tell whether an application uses templates, so
  102.     the instantiation mechanism must cast its net widely. If the default
  103.     repository exists and has a non-empty defmap file in it, the pre-linker is
  104.     called.
  105.  
  106. Reading this in combination with the following which refers to the use of
  107. multiple repositories:
  108.  
  109.   Selecting Readings page 7-10
  110.  
  111.     Type lookup in map files follows the algorithm in the section above on
  112.     user overriding of name mapping files, except that the algorithm is
  113.     applied in total to each repository left to right until the type is
  114.     found.
  115.  
  116. you might conclude that if the first repository doesn't include a non empty
  117. defamp file but a subsequent directory does then things may work, however
  118. what I haven't found is any mention of the fact that instatiation will occur
  119. even when you have no defmap files but do have nmap files.
  120.  
  121.  > We have found it useful to create archive libraries that utilize
  122.  > templates in three steps:
  123.  > 
  124.  >   1) create the archive library
  125.  >   2) compile a dummy main program and link it against the archive
  126.  
  127. There isn't actually a need to supply a dummy main routine as the link will
  128. simply fail with main undefined. It will still compile everything you need
  129. though.
  130.  
  131.  >   3) redo the archive to include all of its original object files plus
  132.  >      the object files created by the template instantiation system
  133.  > 
  134.  > This approach prevents archive library clients from having to perform
  135.  > template instantiation for that archive.  A similar approach is
  136.  > mentioned in the cfront 3.0 release notes, I think.  Makes sense and
  137.  > saves a lot of needless instantiation time.
  138.  
  139. We also make use of nmap files as local conventions mean that header files
  140. don't necessarily have the same names as classes nor are they located in a
  141. top level include directory but could be in a subdirectory. It is helpful
  142. to have tools which can generate the nmap files and a make environment
  143. which knows to go looking for them and stick them in the repository
  144. directory.
  145.  
  146. Although not directly providing a solution to the original poster I hope the
  147. extra information I have provided is of some assistance to someone. The area
  148. of template instantiation is certainly tricky if you try to do things in
  149. anything but the simplest way so any information can help.
  150.  
  151. -- 
  152. Graham Dumpleton (grahamd@swdev.research.otca.oz.au)
  153.