Why is it not good practice to include source files in other source files? It is best to include header files. What are the advantages of this approach and what are the disadvantages of the opposite? Sorry my bad english.
Why is it not good practice to include source files in another source? files?
Source files contain definitions. They can cause several definition errors , and therefore should usually not be included in other source files. Even if you avoid multiple definition errors by compiling only files that include another source file, the code may become unmanageable.
. .
:
a.c
int a = 42; ...
b.c
/* Example of bad code */ #include "a.c" ...
a.c b.c , multiple definition.
multiple definition
, (, ..), - .
p.s. , , . , , , .c, .inc .
.c
.inc
, C C . , .
, , C , . , c-, C unit test.
. :
, (++): https://isocpp.org/wiki/faq/templates#separate-template-fn-defn-from-decl
#include d , #include pre. . -.
#include
, . , / . , , / .
: , . inline, .
inline
, , , . static, . , . , . #include d, static. . .inc .h.
static
.h
. "JPG", # , .
, , , #include , /. , - (, 50 ).
, ( ), , . , , , , . , , , , , , , , .
, , , , (, , ), , / () / ().
, , , , , , .
c , , int add(int, int), ,
int add(int, int)
int add(int x, int y) { return x + y; }
, , , , .
c, , add(), .
add()
,
int add(int x, int y);
, add().
, , , c ?
, , .