PDA

View Full Version : Correct format for header files?


Mars_999
2002.07.10, 04:27 PM
I can't remember what the rule is on header files?


#ifndef Includes_h
#define Includes_h

#include <iostream>

#endif


or


#ifndef _Includes_h
#define _Includes_h

#include <iostream>

#endif


I thought that the compiler reserved some naming convention for headers? Just want to do it right the first time. Thanks

Johan
2002.07.10, 04:40 PM
Use "#define WHATEVER_H". I heard somewhere that it's unwise to use the leading underscore since most compilers use that for internal stuff. Better to be on the safe side, right?

You can also use #pragma once. I usually do both.

.johan

OneSadCookie
2002.07.10, 04:47 PM
It's not just a rule for header guards, but for everything you write (macros, variable, function & type names, &c):

Anything containing a double-underscore (__) is reserved for the compiler.

Anything beginning with a single underscore followed by an upper-case letter (eg. _I) is reserved for the compiler.

Anything beginning with a single underscore is reserved for the compiler in C/ObjC, and reserved for the compiler if it is not inside an explicit namespace in C++. Notice that macros (eg. header guards) are never in a namespace.