Avoid double inclusion: preprocessor directive against makefiles

I am working on the transition from Frankenstein and single-file programs to thousands of lines into well-structured and organized multi-file programs. Currently, what seems natural (naive) is to create a love triangle of headings for my three files:
file_1 includes file_2, file_4
file_2 includes file_3, file_4
file_3 includes file_1 .... etc. etc.
These files have variables, methods, structures, etc., which I need between other files.

And of course, I get double inclusion errors.

My question is: should these problems be avoided by using preprocessor directives in the headers (for example, including structures, methods, etc. entirely in the header), or should I compile using the makefile (which I hear can also be used to solve this problem, but I never did that)?

+5
source share
4 answers

, .., - . Makefiles , . :

  • shared variable extern ( .c)
  • ( .c)

#IFNDEF #ENDIF, .c...

+3

, . Makefile , .

, , .

+13

"inv_tree.h"

#ifndef INV_TREE_H
#define INV_TREE_H
...
#endif

"inv_tree.h" , , INV_TREE_H "inv_tree.h". , "inv_tree.h",

+1

, . , , .

, forward ( heder).

.

: , , head.

+1