Thread: C++ std routines

  1. #31
    System Novice siavoshkc's Avatar
    Join Date
    Jan 2006
    Location
    Tehran
    Posts
    1,246
    >>Due to the complexity of the feature, though, no compiler I'm aware of fully implements it.
    >>But if one did, it could use a standard library where the linker resolves std::vector.
    Can you explain me why it is complex?
    [EDIT]
    From the posts I got, I made another question: Does C Standard Liberary use Windows API to do its work in Windows environment?
    Last edited by siavoshkc; 07-27-2006 at 11:11 AM.
    Learn C++ (C++ Books, C Books, FAQ, Forum Search)
    Code painter latest version on sourceforge DOWNLOAD NOW!
    Download FSB Data Integrity Tester.
    Siavosh K C

  2. #32
    Registered User
    Join Date
    Aug 2002
    Location
    Hermosa Beach, CA
    Posts
    446
    Does C Standard Liberary use Windows API to do its work in Windows environment?
    The short answer is yes. The long answer is that the source code for the c standard library is probably on your machine, check: C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\crt\src, or some similar directory, depending on which version of Visual Studio you are running.
    The crows maintain that a single crow could destroy the heavens. Doubtless this is so. But it proves nothing against the heavens, for the heavens signify simply: the impossibility of crows.

  3. #33
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    Quote Originally Posted by siavoshkc
    Can you explain me why it is complex?
    The classical compile process looks like this: first, you take each .cpp file, preprocess it (and thus add all the .h files) and compile it to an object file (.o or .obj, typically).
    Then, you take these object files and link them together.

    With the extern template feature, this doesn't work. The compiler needs to instantiate templates, and it needs to know about the usage of the templates to know with which types to instantiate them. That's why, currently, all code of templates must be in the headers: so that the compiler can instantiate them upon their use.
    If you want to have them in completely independent files, the compiler must keep statistics about which templates are implemented where, and how they are used. Upon each template use, the compiler would have to find out where the template is implemented, see if it has already been instantiated with that specific type, if it hasn't been, parse the template implementation and instantiate it, then record the instantiation in the statistics. Or alternatively, it could, upon coming across a template implementation, save it to a temporary file, upon encountering an instantiation log that, and after everything else is done, look at the instantiation log and create all instantiations. Of course, if one of the templates in turn uses another, that must be handled too.

    So you see, it's a significant deviation from the current model and thus very complex to implement. And leaving aside the compiler and linker themselves, you have to consider build tools that need to handle all those files the compiler generates: does it create one object file per instantiation, or one object file for all instantiations of a template? What should be done with the statistics files?

    And I'm still oversimplifying. Only those parts of a template class that are actually used get instantiated. A compiler must record each single function individually, not whole template classes at once.

    That's what I can tell you from the viewpoint of a C++ programmer who excels in theory and has done a bit of compiler development - a real compiler developer could probably tell you even more.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  4. #34
    System Novice siavoshkc's Avatar
    Join Date
    Jan 2006
    Location
    Tehran
    Posts
    1,246
    Thanks CornedBee.
    I will look at /src.
    Learn C++ (C++ Books, C Books, FAQ, Forum Search)
    Code painter latest version on sourceforge DOWNLOAD NOW!
    Download FSB Data Integrity Tester.
    Siavosh K C

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Why std:: and not using namespace std?
    By swappo in forum C++ Programming
    Replies: 4
    Last Post: 07-03-2009, 03:10 PM
  2. std:: or namespace std
    By C-+ in forum C++ Programming
    Replies: 16
    Last Post: 12-04-2007, 12:30 PM
  3. Builder 5 v's bcc32.exe
    By sononix in forum C++ Programming
    Replies: 3
    Last Post: 08-17-2004, 10:17 AM
  4. Site tutorials
    By Aalmaron in forum C++ Programming
    Replies: 20
    Last Post: 01-06-2004, 02:38 PM
  5. Special Allegro Information
    By TechWins in forum Game Programming
    Replies: 12
    Last Post: 08-20-2002, 11:35 PM