home *** CD-ROM | disk | FTP | other *** search
- Xref: sparky gnu.g++.help:1441 comp.lang.c++:16337
- Path: sparky!uunet!gumby!destroyer!cs.ubc.ca!pacific.cs.ubc.ca!not-for-mail
- From: upham@cs.ubc.ca (Derek Upham)
- Newsgroups: gnu.g++.help,comp.lang.c++
- Subject: Re: Where do templates go?
- Date: 15 Nov 1992 18:45:22 -0800
- Organization: Raven's Auto Body Repair Shop, Mega-Tokyo.
- Lines: 51
- Message-ID: <1e7202INN4rt@pacific.cs.ubc.ca>
- References: <DECHC00.92Nov13122503@tohi.DMI.USherb.Ca> <1992Nov13.185422.28026@muddcs.claremont.edu> <DECHC00.92Nov15134442@tohi.DMI.USherb.Ca>
- NNTP-Posting-Host: pacific.cs.ubc.ca
-
- dechc00@tohi.DMI.USherb.Ca (CHRISTIAN DECHAMPLAIN) writes:
-
- >I understand the reasons why nobody wants to change the linkers, then how
- >about a pre-linker!
-
- That's what I was thinking. The C++ compiler already uses stabs (or
- whatever) to map object code back to the original source files; it
- should be possible to use the same features for generating templates.
- Have the compiler generate stabs information that points template
- symbols back to the original header files. Just before the usual
- linking, a pre-linker sweeps through all the object files and looks
- for unresolved template symbols (the mangler should make template
- symbols obvious). The pre-linker does consistency checks, then
- compiles the template source files for every needed case, without
- duplication. After it's done, it strips the stabs info out of the
- original object files and calls the "regular" linker. To save time,
- there might be an option to save the automatically generated ".o"
- files in the compilation directory.
-
- There are a couple of simple ways of finding the definitions/source
- code with this method.
-
- * the library writer could just stick them into the header file (which
- would probably be compatible with the current G++ method---oh boy).
- The compiler would keep track of template definitions that it saw, but
- otherwise would just ignore them until pre-link time (at which point
- the header file would be interpreted as a regular source file).
-
- * the compiler could assume that if the header file was
- "/usr/include/foo.hh", then the corresponding source file would be
- named "/usr/include/foo.cc" (Dialect Alert!), stored in the same
- directory; the pre-linker would just look through the same set of
- #include directories as the pre-processor (which does mean the current
- directory as well).
-
- * To be really sure, the library writer could add a #pragma directive
- of some sort to the header file. This would also be helpful as a
- supplement to the other two.
-
- The first method has a slight edge in that it's a bit more
- idiot-proof. It should also deal more gracefully with the case of a
- template function (as opposed to a template class with template
- members) that is defined and used throughout a single ".cc" file.
-
- Derek
-
- --
- Derek Lynn Upham University of British Columbia
- upham@cs.ubc.ca Computer Science Department
- =============================================================================
- "Ha! Your Leaping Tiger Kung Fu is no match for my Frightened Piglet Style!"
-