Situation
I'm using min GW compiler:
>bin\cpp --version
cpp.exe (GCC) 6.1.0
Copyright (C) 2016 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
I have two header files main.h
and submodule.h
. For various reasons I cannot simply include one of this headers into the other.
[update]
I think you need to explain the various reasons why you cannot simply include one of this headers into the other because that's the obvious answer... – Andrew
I cannot import
main.h
intosubmodule.h
because in that case a change inmain.h
would trigger a recompilation of the submodule althoug nothing changed here. Compile time is a major concern for my client.I cannot include
submodule.h
intomain.h
becausesubmodule.h
defines lots of stuff but only a few definitions are public. My client wants to reduce visibility of identifiers as much as possible.My client uses the content of
main.h
to verify compatibility of different versions of the target software. Existence and size of the mentioned array is one of the compatibility criteria. Therefore the definition of the array must stay inmain.h
There are some versions of the target software that do not have the submodule at all. Therefore the files building this submodule may or may not be present. There is a lot of overhead (for my client) to deal with that situation which has to be done by someone else, not me. So my client also wants to limit the number of "flickery" files.
I also have lots of other *.h
files that include main.h
but not submodule.h
, and they should not to hide some things in the sub module.
The submodule.h
defines lots of stuff implemented in submodule.c
.
Among that is an array type definition and a global variable of that type:
typedef const char INDEX_TABLE_t[42];
const INDEX_TABLE_t INDEX_TABLE;
The submodule.c
implements this array:
const INDEX_TABLE_t INDEX_TABLE {/* 42 random char values */};
The variable INDEX_TABLE
ist used in that other *.h
files:
char SOME_OTHER_INDEX[23] = {/* 23 random char values */};
#define SELECTOR_VALUE 5
#define a_fix_name INDEX_TABLE[SOME_OTHER_INDEX[SELECTOR_VALUE]]
these *.h
files include main.h
but not submodule.h
.
Therefore I used to add the (exact same) type definition of INDEX_TABLE_t
and INDEX_TABLE_t
to main.h
which compiles fine.
Problem
My client uses a code alaysis tool (QA-C) that complains about the doubled definition of the type INDEX_TABLE_t
.
[C] More than one declaration of 'INDEX_TABLE_t' (with no linkage).
The client instructed me to change the code so that this error will no longer issued by the code analysis tool.
I usually solve this by adding the extern
keyword to all but one occurrence.
But in this case the compiler throws an exception:
error: conflicting specifiers in declaration of 'INDEX_TABLE_t'
But the declaratios are equal (they are rendered based on a model).
Questions
Do I have any chance to make both happy, the compiler and the code analyser?
Is createing another header file to be included in in main.h
or all the other *.h
files my only option?