header files in general

This is a discussion on header files in general within the C++ Programming forums, part of the General Programming Boards category; When you include a header file, does it always include the whole thing, or only the parts that are used?...

  1. #1
    Registered User
    Join Date
    Sep 2002
    Posts
    417

    header files in general

    When you include a header file, does it always include the whole thing, or only the parts that are used?

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    The entire thing is included. (Assuming you aren't doing something fancy with #defines, but other than that, yes.)

    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Registered User
    Join Date
    Sep 2002
    Posts
    417
    I think thats kind of stupid... it'd be more memory efficient not to... but it'd take longer to compile I guess

  4. #4
    Student Forever! bookworm's Avatar
    Join Date
    Apr 2003
    Posts
    132
    I was thinking of posting this question for a long time.Instead of starting a new thread,I will ask it here itself.
    Y is it advised to use header files for classes instead of making them inline?I mean,the compiler will read the whole thing in both the cases,isn't it?
    (Hey! Guess wat!This is my 50th post!)

  5. #5
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    You post count says 49...


    Anyway: header files only contain declarations, and those don't need memory. The compiler always compiles the whole header file, but that doesn't make for memory consumption.
    It is the linker that is responsible for ignoring unused functions and variables. Most linkers do it.

    Y is it advised to use header files for classes instead of making them inline?
    You mean why not put it in the cpp files directly?
    So that other cpp files can use it too of course.
    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

  6. #6
    Registered User
    Join Date
    Apr 2003
    Posts
    2,662
    "Y is it advised to use header files for classes instead of making them inline?I mean,the compiler will read the whole thing in both the cases,isn't it?"

    It's my understanding that when a function is inlined, the compiler replaces every call to that function with the actual code, so for short functions, it can be more efficient to do that. At some point though, with longer functions and lots of calls, I assume the efficiency of inlining is lost and function calls are more efficient.

  7. #7
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    The inline keyword is only a recommendation though, it's up to the compiler if the function actually gets inlined.

    But I don't think this "inline" is the inline he meant.
    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

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C Header Files
    By devarishi in forum C Programming
    Replies: 8
    Last Post: 12-10-2008, 04:53 PM
  2. Header files in .h
    By swgh in forum C++ Programming
    Replies: 5
    Last Post: 05-29-2008, 09:58 AM
  3. Linking header files, Source files and main program(Accel. C++)
    By Daniel Primed in forum C++ Programming
    Replies: 3
    Last Post: 01-17-2006, 11:46 AM
  4. Missing header files and libraries with Borland
    By quagsire in forum C++ Programming
    Replies: 5
    Last Post: 03-26-2003, 06:19 AM
  5. more header files
    By Unregistered in forum C++ Programming
    Replies: 2
    Last Post: 10-28-2001, 01:56 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21