I have three files
File "grandparent.h"
#ifndef GRANDPARENT_H
#define GRANDPARENT_H
struct foo {
int member;
};
#endif /* GRANDPARENT_H */
File "parent.h"
#include "grandparent.h"
File "child.c"
#include "grandparent.h"
#include "parent.h"
Wiki says
Here, the first inclusion of "grandparent.h" causes the macro GRANDPARENT_H to be defined. Then, when "child.c" includes "grandparent.h" the second time, the #ifndef test returns false, and the preprocessor skips down to the #endif, thus avoiding the second definition of struct foo. The program compiles correctly.
q1. "the first inclusion of "grandparent.h" causes the macro
GRANDPARENT_H to be defined", So what i understand i its basically defining a macro named GRANDPARENT_H
but what i dont understand is that how will the content of that macro (i.e GRANDPARENT_H) would be included in the child.c.
We are just defining the macro GRANDPARENT_H i.e
#define GRANDPARENT_H
struct foo {
int member;
};
but how will its content i.e
struct foo {
int member;
};
be included in the child.c