header files in C++

C, C++, Visual C++, C++.Net Topics
Post Reply
SukhdeepMankoo
Lieutenant
Lieutenant
Posts: 92
Joined: Tue Oct 27, 2009 7:50 pm

header files in C++

Post by SukhdeepMankoo » Wed Jun 02, 2010 3:09 pm

I have seen header files in c++ are without *.h extension.while extension is preserved in c. why need to declare header files without any *.h extension? what will its benefit.

Thanks
User avatar
Neo
Site Admin
Site Admin
Posts: 2642
Joined: Wed Jul 15, 2009 2:07 am
Location: Colombo

Re: header files in C++

Post by Neo » Wed Jun 02, 2010 5:05 pm

Though .hpp is used in some of the modern C++ environments, .h is inherited and still used under C++. So practically you can use either .h or .hpp for header files under C++. But I don't think the extension of the header file matters at all as those are not getting compiled (Just added to the source file where #include directive appears).

However, you will have to use .CPP for C++ source files since C/C++ compilers mostly detect the compilation method based on the extension.
SukhdeepMankoo
Lieutenant
Lieutenant
Posts: 92
Joined: Tue Oct 27, 2009 7:50 pm

Re: header files in C++

Post by SukhdeepMankoo » Wed Jun 02, 2010 5:25 pm

Thanks.
But i have also seen header file, where it does not have any extension.what abt that? why header files do not carry any extension.
User avatar
Neo
Site Admin
Site Admin
Posts: 2642
Joined: Wed Jul 15, 2009 2:07 am
Location: Colombo

Re: header files in C++

Post by Neo » Wed Jun 02, 2010 6:00 pm

That's alright. As said before, when you put the #include directive, the header file will be placed on your source file, that's all. So it can have any extension or no extension at all.
SukhdeepMankoo
Lieutenant
Lieutenant
Posts: 92
Joined: Tue Oct 27, 2009 7:50 pm

Re: header files in C++

Post by SukhdeepMankoo » Fri Jun 04, 2010 12:20 pm

Thanks Neo.
Post Reply

Return to “C/C++ Programming”