The inclusion of a header file with declarations is the main, recommended and used almost anywhere, way to create consistent declarations between the project. The inclusion of another source file is another (very rare) kind of beast, and it is useful and possible under certain conditions:
- There is a reason to split the code into separate source files, even though it must be compiled as a single module. For example, there are different versions of some functions that should not be visible from other modules. Thus, they are declared
static , but which version is included is governed by compilation options. Another option is the issue of credentials in terms of size and / or accounting. - The included file does not compile on its own as a project module. Thus, its exported definitions do not conflict with the module in which the file is included.
Here I used a definition of terms and a declaration such that the following declarations:
extern int qq; void f(int); #define MYDATATYPE double
and the following definitions:
int qq; // here, the variable is allocated and exported void f(int x) { printf("%d\n", x); } // the same for function
(In addition, declarations include C ++ methods with bodies declared inside their class definition.)
In any case, the case is different .c / .cxx / etc. the file is included in the source file, it is very confusing and should be avoided until a real need arises. Sometimes a specific suffix (such as .tpl) is used for such files to avoid confusion for the reader.
Netch source share