c++11 - C++ header guard syntax -


for file name a.h... i've used

#ifndef a_h #define a_h #endif 

but see in tutorials

#ifndef __a_h_included__  #define __a_h_included__  #endif 

and also

#ifndef _a_h_included  #define _a_h_included #endif 

so wondering what's going on... has changed in never versions of c++ or compiler dependent?

i use mingw (gnu gcc g++) , msvc...

edit:

in case there confusion why asked, believe quite confusing novices. example, file named a.h don't say

#ifndef a.h #define a.h 

or even

#ifndef a_h #define a_h a.h 

that make sense me.

instead a_h... or 1 of variants above. therefore, think not syntax ok. used think has file name in caps , period has replaced _. how saw being taught years. no see words _included ... not part of a.h file name in way... confusing... how compiler reconcile a_h_included refers a.h? don't see why down voted think it's quite confusing.

also, 1 person has stated of these variants not standards compliant, therefore think valid question , should not down voted.

or case #define a_h dumps code header file a_h macro? thought define ends @ new line character... in case define a_h no value. in case a_h name no value , question remains how compiler know you're talking file a.h when use funky empty marco variable a_h_dingdong ?

there's been no relevant change in language. identifier used in include guard identifier. in fact entire include guard mechanism not defined language; it's convention.

the issue identifiers starting 2 underscores, or 1 underscore , uppercase letter, reserved implementation. means if use name __foo_h__ in code, it's @ least possible compiler has predefined own internal purposes, , code break in undetermined manner.

tutorials tell write:

#ifndef __a_h_included__  #define __a_h_included__  #endif 

are giving poor advice.

one more subtlety: macro names starting e , digit, or e , uppercase letter, reserved use in <errno.h> / <cerror> header. if header file called earth.h , write:

#ifndef earth_h #define earth_h #endif 

then in principle collide earth_h error number.

that's not happen, , _h suffix enough prevent it, convention use avoid altogether is:

#ifndef h_earth #define h_earth #endif 

you suggest:

#define a.h 

a macro name must single identifier. defines macro a value .h.

#define a_h a.h 

since macro tested using #ifndef, doesn't matter @ value has, whether it's defined or not.


Comments

Popular posts from this blog

sql server - Cannot query correctly (MSSQL - PHP - JSON) -

php - trouble displaying mysqli database results in correct order -

C++ Linked List -