What is the H file format?
.h files are created when working with C, C++ or Objective-C languages.
Contents of .h files
Files with the .h extension contain function declarations or macros, and can hold such data as:
- variable and constant declarations,
- struct, enum, and type definitions,
#includereferences to other header files
In practice, .h files are used to hold shared declarations - code that is referenced frequently across multiple .c and .cpp source files. This allows for better source code legibility and programmer efficiency. Functions and macros defined in .h files make them reusable across projects and facilitate code sharing. This also makes it easier to update the code, as the interface is stored in a single, well-known place.
How are .h files used?
Storing shared declarations in .h files makes them easier to access and add to project source code. During compilation, the C preprocessor expands each #include directive, copying the header's contents into the translation unit before the compiler continues. System headers such as <stdio.h> or <vector> ship with the compiler and do not need to be distributed with your project; project-specific .h files, however, are part of the source tree and travel with it. Many C++ projects also use .hpp files to distinguish C++-only headers from plain-C .h headers, though both rely on the same #include mechanism.
Security & safety
RISK: LOWA .h header is plain-text source code and does not execute by itself, so opening or reading one in an editor is safe. The real-world caution is about COMPILING, not the file format: header (and source) code from an untrusted project can contain malicious logic that only runs once you build and execute the program, so review and build unknown C/C++ code only in a sandbox/VM and from sources you trust. There is no risk in simply viewing the text. (Headers can also #include system files and define macros that change how dependent code compiles - relevant to developers, not a security threat from the file alone.)
Format details
in a nutshell- Objective-C / Objective-C++ header - Apple's Objective-C also uses .h headers (e.g. declaring @interface classes), opened the same way in Xcode/text editors.
- ch / various app data - A handful of niche programs (and old game/data tools) reuse .h for non-source data; identify by the file's contents, not the extension.
Programs that open H files
Technical details
deep spec| File type | Plain-text source-code header |
| MIME type | text/x-c |
| File signature (magic bytes) | None - plain text, identified by extension and content |
| Typical opening construct | Include guard (`#ifndef NAME_H` / `#define NAME_H`) or `#pragma once` to prevent multiple inclusion |
| Preprocessor role | Expanded inline by the C preprocessor before compilation; `.h` files are not compiled directly |
| Include syntax | System headers use angle brackets (e.g., `<stdio.h>`); project headers use double quotes (e.g., `"mylib.h"`) |
| Typical contents | Function declarations, macro definitions, struct and enum definitions, typedef aliases, and (in C++) class declarations |
| Related extensions | `.c`, `.cpp`, `.hpp`, `.hxx`, `.hh`, `.cc`, `.cxx` |
| C++ linkage | C headers included in C++ code are often wrapped in `extern "C" { }` blocks to prevent name mangling |
| Character encoding | ASCII (historical norm); UTF-8 widely accepted by modern compilers for identifiers and comments |
| Multiple-inclusion protection | Include guards or `#pragma once` ensure the same header is processed only once per translation unit |
| Standard C library headers | Follow the `<name.h>` convention, e.g., `<stdio.h>`, `<stdlib.h>`, `<string.h>` |
| Template definitions (C++) | Function and class templates must be fully defined in header files since they are instantiated at compile time |
| Released | 1972 (C language; #include header convention from early C) |
| Open standard | Yes · royalty-free |
| Specification | en.cppreference.com |
H conversions
Community Q&A
asked by usersNo questions yet - be the first to ask about H files.