while I am creating a c++ header file, I declare the header file like;
/*--- Pencere.h ---*/
#ifndef PENCERE_H
#define PENCERE_H
I want to learn that why do I need to write underline.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You don’t need to use the underline, it’s just a convention to separate the header name and extension. You cannot use the literal
.since that’s not valid in an identifier so you replace it with an underscore which is valid.The reason you actually do it is as an include guard. The entire contents of the file are something like:
so that, if you accidentally include it twice:
you won’t get everything in it duplicated. The double inclusions are normally more subtle than that – for example, you may include
pax.handdiablo.hin your code andpax.halso includesdiablo.hfor its purposes:In this case, if the include guards weren’t there you would try to compile the line
typedef int mytype;twice in your program. Once formain.c -> pax.h -> diablo.hand again formain.c -> diablo.h.With the include guards, the pre-processor symbol
DIABLO_His defined whenmain.cincludesdiablo.hso the#defineandtypedefare not processed.This particular mapping of header files to
#definenames breaks down in the situation where you havedir1/pax.handdir2/pax.hsince they would both usePAX_H. In that case, you can use a scheme likeDIR1_PAX_HandDIR2_PAX_Hto solve the problem.