0

I'm following this tutorial about the basics of Code::Blocks projects. To use multiple files in a project, you need a header file. This section gives the source code for the most basic of header files, but gives no explanation.

#ifndef HELLO_H_INCLUDED
#define HELLO_H_INCLUDED

void hello();

#endif // HELLO_H_INCLUDED

I got curious about the significance of HELLO_H_INCLUDED. I changed it to various names, and the project parsed and ran properly regardless of what I named it.

However, if you delete HELLO_H_INCLUDED entirely, it an error arises saying no macro name given in #ifndef directive.

So, explain to me like I'm five years old: What is a macro name, what does it do, and why is it required?

Johan
  • 343
  • 1
  • 4
  • 13
  • What you have is known as an include guard. That's the term to look for. Removing the identifier part of it is simply wrong because `#ifndef` (shorthand for `#if not defined`) needs a name in order to check whether it's not defined. – chris Feb 03 '15 at 20:02
  • 2
    Maybe not the best dupe to find, but there are many explanations what these so called _header or include guards_ are doing, and why they are useful. Even [wikipedia](http://en.wikipedia.org/wiki/Include_guard) explains it – πάντα ῥεῖ Feb 03 '15 at 20:03

0 Answers0