© The Author(s), under exclusive license to APress Media, LLC, part of Springer Nature 2024
S. DmitrovićModern C for Absolute Beginnershttps://doi.org/10.1007/979-8-8688-0224-9_47

47. What to Put in Header Files?

Slobodan Dmitrović1  
(1)
Belgrade, Serbia
 
This chapter explains what to and what not to keep in header files. In general, when we want to share data between multiple source files, we create a common header file and include it in each source file. For the following examples, we will use two source files and one common header file:
  • myheaderfile.h – Shared header file

  • source.c – Main source file

  • source2.c – Second source file

A good practice is to guard the content of the myheaderfile.h file with the include guards/header guards:
#ifndef MYHEADERFILE_H ...

Get Modern C for Absolute Beginners: A Friendly Introduction to the C Programming Language now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.