I have been seeing code like this usually in the start of header files
#ifndef HEADERFILE_H
#define HEADERFILE_H
and at the end of the file is
#endif
I am confused about the purpose of this ..?
I have been seeing code like this usually in the start of header files
#ifndef HEADERFILE_H
#define HEADERFILE_H
and at the end of the file is
#endif
I am confused about the purpose of this ..?
Those are called Include guards.
Once the header is included, it checks if a unique value (in this case HEADERFILE_H
) is defined. Then if it's not defined, it defines it and continues to the rest of the page.
When the code is included again, the first ifndef
fails, resulting in a blank file.
That prevent double declaration of any identifiers such as types, enums and static variables.