Ducklett
Ducklett

Reputation: 73

How to include a header privately in C

How to include a header file in c privately so that files that include the file that includes the header wont include the header.

for example:

main.c

#include "main.h"

main.h

#include "test.h"
// I want main.c not to include test.h

I would like to know how to do that

Upvotes: 1

Views: 206

Answers (1)

Jean-François Fabre
Jean-François Fabre

Reputation: 140168

use a #define:

in main.c

// the define MUST be before main.h inclusion
#define IN_MAIN_C
#include "main.h"

in main.h

#ifndef IN_MAIN_C
#include "test.h"
#endif

Upvotes: 3

Related Questions