c++ - Avoiding double inclusion: Preprocessor directive vs. makefiles -


i'm working on moving frankenstein , one-file thousands-of-lines programs structured , organized, multi-file programs. right seems natural (naively) make love-triangle of header inclusions 3 of 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, structs, etc need between other files.

and of course i'm getting double inclusion errors.

my question: should avoid these problems using preprocessor directives in headers (e.g. including structs, methods, etc. entirely in header), or should compiling using makefile (which hear can used resolve problem---but i've never made one)?

preprocessor directives , headers containing declaration , shared structures etc way go. makefiles helps compile sources , link object files external libraries form final binary, won't resolve multiple-inclusion issue. in nutshell, declare following in header file:

  • structs
  • shared variable extern (and define in 1 of .c files)
  • method declaration (and define methods in 1 of .c files)

protect them #ifndef , #endif, include header file various .c files...


Comments

Popular posts from this blog

javascript - Enclosure Memory Copies -

php - Replacing tags in braces, even nested tags, with regex -