#ifdefine question

When I coding my program in separate files, I use definition macro for file test.h like this:

//------------
#ifndef TEST_H
#define TEST_H
.....
.....
#endif
//---------------

Since I'm a newbie I don't know, should I use a definition name like my file name as TEST_H? What if I use another name? Is there any rolls for this?
There is no any difference. Only it gives some additional information about used header file.
The only thing that you want to consider is making sure its unique. In hierarchical codebases, you may want to add the relative path before the file name in case you have two test.h (such as app/test.h and lib/test.h).
closed account (zb0S216C)
Calcushtag wrote:
#ifndef TEST_H

Personally, I hate this style of header guard. I prefer either one of these:

1
2
3
4
5
#ifndef __MY_HEADER_IMPL__

// Or:

#if !defined __MY_HEADER_IMPL__ 

I do agree with moorecm, though.

Wazzak
> The only thing that you want to consider is making sure its unique.

If the code base is a large one, it is a good idea to generate the include guard token from the base name of the header file. Compilers (actually preprocessors) would then be able to enable the multiple-include optimization.

For example, see: http://gcc.gnu.org/onlinedocs/cppinternals/Guard-Macros.html
Topic archived. No new replies allowed.