Hello everyone I want to ask a question about including guards in C programming. I know their purpose but in some programms I have seen a 1" written after #define like this:
#ifndef MYFILE_H
#define MYFILE_H 1
What is the purpose of this 1? Is it necessary?
It is not necessary if the
MYFILE_Hmacro is not used elsewhere in your code.If it is used elsewhere with an
#ifdefor#ifndefdirective like here:then the
1is not required in the macro definition-but it if it used elsewhere with an
#ifdirective like here:then the
1(or any value!= 0) is required in the macro definition.Note these directives could be used in a source file to verify if the header is included or not.