If i put a #define NAME 100 inside a file.cpp instead of a file.h, is it visible only in file.cpp (or also in other moduules)??
If i put a #define NAME 100 inside a file.cpp instead of a file.h, is it visible only in file.cpp (or also in other moduules)??
Unless you're doing something dumb like including source files in other source files, then your #define is limited to that single source file.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
ok so basically if i want a "global" #define i put it in a file.h (and then include it where needed) and if i want a "local" #define i can put it in a file.cpp
Exactly.
Remember that all that "#include <file.h>" does is get the preprocessor to stop reading from your source file and start reading from file.h, effectively stuffing the contents of file.h into your original source file. The resulting plain file (i.e. with no #include directives remaining) is what actually gets compiled.