© Slobodan Dmitrović 2021
S. DmitrovićModern C for Absolute Beginnershttps://doi.org/10.1007/978-1-4842-6643-4_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
#define MYHEADERFILE_H
// code goes here
#endif

47.1 Shared Macros ...

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.