header files

Some of the examples I've seen for how-to-use header files use capitalisation for the file name in the include guard.

#ifndef _NAME_H
#define _NAME_H

I can't find a explanation for this, nor does it seem to make any difference in my sketch. Is there any reason or convention?

And I assume that the _H refers to the .h file extension, but what is the significance of the underscore before the file name?

The actual name that you define does not matter as long as it unique. Using a capitalised version of the filename preceded with an underscore makes this more likely but it can actually be anything

They are just arbitrary unique names. There is no magic to this. The use of the filename converted to UPPERCASE_WITH_UNDERSCORES is a common approach, and gives some hope of uniqueness.

As for the leading underscore, probably that's just a quirk of a few developers. This is actually not a good thing to do because all identifiers that begin with an underscore followed by an uppercase letter are reserved in C++ and use of these identifiers results in undefined behavior.

it's common practice to CAPITALIZE constants, in particular #defines and never Capitalize variables, function names, ...

gcjr:
never Capitalize variables, function names, ...

Well ..... Camel case - Wikipedia

camelCase variables, CamelCase Constants

Thanks.

To get an idea about the minefield you have just walked in to..

See Tabs vs Spaces

-jim lee

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.