Thread: headers simplified...please

  1. #16
    Registered User
    Join Date
    Oct 2007
    Posts
    14
    tabstop,

    Thats a good point. I took a look at cmath and it leads to more include files. There was some implementation in the cmath file, actually a lot. I followed the included files which lead to more code and more included files. So how does this eventually lead to pre-compiled objects and libraries?

  2. #17
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    I have gcc 3.4.5 (at least here on this Windows machine), so maybe there's differences: in my cmath file, I have a lot of "code" that changes the name back to the old-style C names (so asin may go to asin, or asinf, or asinl -- actually with the _builtin__ prefix), but neither c++config.h, cmath.tcc, cpp_type_traits.h, or math.h had any source for any of those functions.

    The compiled source for all of those is in libm.a in your lib subdirectory (and if you #include <cmath>, you need to compile with -lm at the end on *nix -- there's a reasonably well-known bug in gcc about that).

  3. #18
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Here's the deal:
    my_class.h contains the class definition, and does not under any circumstances include any .cpp file. C/C++ doesn't work that way.
    my_class.cpp should include my_class.h.
    Every other source file that uses my_class should include my_class.h.
    No file should include my_class.cpp whatsoever.

    You compile all source files.
    You link all object files.
    Or you just use a proper IDE that does all this for you.

    You should never include a .cpp file because they contain function definitions and class implementations, so if you include the same .cpp file twice somewhere, you get linking errors.

    The fact that you can include vector and just use it is because it's located in a library somewhere and you tell the linker to link against that library.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  4. #19
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    I suggest that you do not take <vector> as an example. The <vector> standard header is for the std::vector class template. The rules for templates can be a little different from normal (e.g., Elysia's dictum that one should "not under any circumstances include any .cpp file" does not necessarily apply as one may include the source file with a class template's implementation into its header file).
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. include question
    By Wanted420 in forum C++ Programming
    Replies: 8
    Last Post: 10-17-2003, 03:49 AM
  2. Headers that use each other
    By nickname_changed in forum C++ Programming
    Replies: 7
    Last Post: 10-03-2003, 04:25 AM
  3. how do you handle all your headers?
    By mart_man00 in forum Linux Programming
    Replies: 0
    Last Post: 06-16-2003, 03:17 PM
  4. Help with headers (conio.h etc)
    By ofthedove in forum C++ Programming
    Replies: 2
    Last Post: 02-24-2003, 02:44 PM