Re: About different versions of the same header files



CBFalconer <cbfalconer@xxxxxxxxx> writes:
"parag_paul@xxxxxxxxxxx" wrote:

Suppose I have a huge code base, And I have a very common header
file. Now there are mulitple places where this header file is kept.

This header file cannot be factored as it has different function
prototypes in different places. Now can there be a safeguard at
compile time to maintain the #defines in the different headers
files to be same .

ie suppose I add a new type in one of the header files and then
want that compile fails in the other directories which has the
header file with the same name, unless all the #defines are same
in all.

Don't do that. The only purpose of header files is to allow use of
the C file in other compilations, i.e. to specify the interface.

Not all headers are associated with C files; some just have macro
definitions, typedefs, and so forth. <stdint.h> is an example.

You should have only one copy of such a header, and it should not
change (barring early development). If it needs to appear in
multiple locations consider using links, rather than file copies.
(U/Linux).

I don't see why it would *need* to be in multiple locations. It
should be possible to have one copy in one place, and refer to it from
anywhere within the project.

But the OP's problem is that he's dealing with a huge code base that's
*already* a mess; it's a little late for "Don't do that".

If there are chunks of the header that need (for now) to be different,
and other parts that are still consistent, it probably makes sense to
split the header into two parts, one that's identical across all
copies (or, better, stored in only one place), and another that
reflects the current inconsistencies. This will require updating a
lot of '#include' directives, but it should be possible to automate
that. Over time, try to migrate declarations from the multiple
inconsistent headers into the single shared header, updating client
code as needed. This can be done incrementally, and *eventually* you
should be able to get rid of the multiple inconsistent headers.

--
Keith Thompson (The_Other_Keith) kst-u@xxxxxxx <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
.



Relevant Pages

  • Re: header files including other files
    ... Really I guess I am asking advice about source code organisation. ... Now, in any particular module, the module header file declares exported ... compile it with no errors. ...
    (comp.arch.embedded)
  • Re: [DRIVER SUBMISSION] DRBD wants to go mainline
    ... header file. ... and then include some header after that. ... I want to be able to do a rate-limit per specific message/code fragment, ... When I earlier said I thought I was in macro hell, well, I was ...
    (Linux-Kernel)
  • Re: "I want to ask about c++"
    ... This is called a "header include guard", or simply a "header guard". ... With very rare exceptions, you should not define an object in a header file, nor a non-static function. ... The reservations are restricted only because the second character of the identifier was a 'd'. ...
    (comp.lang.c.moderated)
  • Re: headerfiles and make?
    ... How can I compile using the above makefile when types.h is ... used in your source code tells the compiler to look for it. ... Since a Makefile isn't necessary for compiling a program the header ... rectlive tells the compiler to look for a header file and evaluate ...
    (comp.unix.programmer)