What is H?
H (.h) files are header files in C and C++ containing declarations that can be shared across multiple source files. They typically include function prototypes, struct/class definitions, macros, constants, and type definitions. Header files are included using #include directives and enable separate compilation and code organization.
Header guards (#ifndef, #define, #endif) or #pragma once prevent multiple inclusion of the same header. Standard library headers like stdio.h, stdlib.h, and string.h provide essential functionality for C programs.
History
Header files were introduced with the C programming language in 1972 as a way to share declarations across source files, enabling modular programming and separate compilation.
Key Milestones
- 1972: C language introduces header files
- 1978: Standard C library headers established
- 1985: C++ extends with class declarations
- 1998: C++ standard library headers (no .h)
- Present: Fundamental to C/C++ development
Key Features
Core Capabilities
- Function Declarations: Prototypes for implementation files
- Type Definitions: Structs, classes, typedefs
- Macros: #define preprocessor directives
- Constants: const and enum definitions
- Header Guards: Prevent multiple inclusion
- Templates: C++ generic programming (in headers)
Common Use Cases
Library APIs
Public interface definitions
Shared Code
Declarations across files
Data Structures
Struct and class definitions
Embedded Systems
Hardware register definitions
Advantages
- Enables modular programming
- Code reusability
- Separate compilation
- Clear interface definitions
- Standard practice in C/C++
- Documentation through declarations
Disadvantages
- Declaration/definition duplication
- Header guard boilerplate
- Circular dependency issues
- Compilation time if overused
- Template code bloat in headers
Technical Information
Format Specifications
| Specification | Details |
|---|---|
| File Extension | .h |
| MIME Type | text/x-c |
| Format Type | Source code header |
| Encoding | ASCII or UTF-8 |
| Language | C, C++ |
| Preprocessor | #include directive |
Common Tools
- Compilers: GCC, Clang, MSVC
- Editors: VS Code, Vim, CLion
- Analysis: Clang-tidy, cppcheck