Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++: Reason why using ".hh" as extension for C++ header files [closed]

I would like to know why we use ".hh" as extension for C++ header files instead of using just ".h".

The header files are preprocessed and the preprocessor doesn't even care about the extension of the header file. So, even if I create a header file with an extension ".qwe" (test.qwe). Then, why to use ".hh" as extension for C++ header files.

Some say, we are using ".cc" as extension for C++ files to differentiate from C files (which has an extension ".c"), likewise we are using using ".hh" as extension for C++ header files to differentiate from C header files (which has an extension ".h"). I don't think this to be a valid reason.

Does anyone know the reason for naming in such a way?

like image 822
veda Avatar asked Apr 27 '12 16:04

veda


People also ask

What is .HH file?

What is an HH file? A file with . hh extension is a C++ header file that includes the declaration of variables, constants, and functions. These declarations are used by the corresponding C++ implementation files, usually saved as . cpp files that contain the actual implementation of user logic.

Should I use h or HPP?

You should use the . hpp extension if you're working with C++ and you should use . h for C or mixing C and C++.

Why we use this in C header file?

These preprocessor directives are used for instructing compiler that these files need to be processed before compilation. In C program should necessarily contain the header file which stands for standard input and output used to take input with the help of scanf() and printf() function respectively.

What happens if header files were not used in C program?

Without a header file, you cannot run or compile your program code. In C, all program codes must include the stdio. h header file.


1 Answers

Some say, we are using ".cc" as extension for C++ files to differentiate from C files (which has an extension ".c"), likewise we are using using ".hh" as extension for C++ header files to differentiate from C header files (which has an extension ".h").

That is exactly the reason. It is just to differentiate CPP headers from C headers.

Some programmers and libraries, such as Boost, use .hpp for CPP headers. My personal choice is this:

  • example.c
  • example.cpp
  • example.h
  • example.h++

Even if they all belong to a huge project, you can still figure out which one is which. No description is needed.

like image 183
Nawaz Avatar answered Sep 21 '22 07:09

Nawaz