1

This question is from an idealistic standpoint. // Forward declaration

I've been learning the basics of makefiles and I found myself wondering the same thing that was asked here about header dependencies. From a practical standpoint, I'm glad that there are solutions which solve the problem of header dependencies. However, thinking on the question a bit more, I find myself asking why a header dependency would ever exclusively affect a compilation unit. Under the assumption (see forward declaration) that definitions are contained in headers and implementation is defined in source units, is there any reason that modification to a header file is merited without modification to the respective source file? If not, why does it even matter to recompile the dependent source unit(s) since a definition modification alone will have no affect on program execution? Is it just a question of identifying errors in changes to interface definitions sooner rather than later?

asked Apr 7, 2013 at 15:57

1 Answer 1

1

(To be precise, declarations are contained in header files, and definitions (i.e. implementations) are in source files, but that's just terminology.)

"Is there any reason that modification to a header file is merited without modification to the respective source file?"

Yes. Changing a member from public to private, for example. Also, more than one source file can #include a given header file, so a change to the header might require a change to one of them but not another. For example, adding/removing/renaming a data member in a class might not require any change in the the classes implementation, but still require a change in other source code that uses the class.

Even when a source file hasn't changed at all, it can still be logically necessary to recompile it if a header file has changed. For instance, adding/removing a data member changes the size of a class, which means that any code that uses instances of that class must adjust the amount of memory to allocate for them.

answered Apr 7, 2013 at 16:25
Sign up to request clarification or add additional context in comments.

1 Comment

I didn't think about the case of class size. It seems possible that if header dependencies weren't taken into account when a class definition change affects the class size, this could greatly affect the resulting executable if not all dependent CU's are recompiled. Thanks!

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.