c++ - Need clarification on #ifndef #define -


the code working has multiple headers , source files different classes face.cc, face.hh, cell.cc, cell.hh edge.cc edge.hh , headers contain includes this,

#ifndef cellincluded #define cellincluded  #ifndef faceincluded #define faceincluded 

i saw through http://www.cplusplus.com/forum/articles/10627/ , saw way write include guard

#ifndef __myclass_h_included__ #define __myclass_h_included__ 

so in above code working on, compiler automatically understands looking face.hh or cell.hh files?

better question : writing __cell_h_included__ same cellincluded ?

#ifndef __myclass_h_included__ #define __myclass_h_included__ 

so in above code working on, compiler automatically understands looking face.hh or cell.hh files?

no, compiler doesn't automatically understand mean.

what happens that, when compiling translation unit, compiler holds list of globally defined macros. , so, doing defining macro __myclass_h_included__ if doesn't exists.

if macro defined, #ifndef until #endif not parsed actual compiler. hence can test existence of macro determine if compiler has parsed header file include once , once in translation unit... because compiler compiles each translation unit one flattened file (after merging #includes)

see https://en.wikipedia.org/wiki/include_guard

is writing __cell_h_included__ same cellincluded ?

yes is.... reason prefer using underscored prefixed , suffixed macros include guards because have extremely low probability of ever being used identifiers... again, underscore clash compiler...

i prefer this: cell_h_included

if use cellincluded, there chances someday, may use identifier in translation unit


Comments

Popular posts from this blog

javascript - How to get current YouTube IDs via iMacros? -

c# - Maintaining a program folder in program files out of date? -

emulation - Android map show my location didn't work -