You missunderstood the meaning of "include". This is like copy&paste with sharing code resources.
For example:
#define SUCCESSOR(X) X+1
#define INCREMENT(X) X = SUCCESSOR(X)
#include "file1.h"
#include "file2.h"
void main()
{
int value = 5;
INCREMENT(value);
}
that looks like:
#define SUCCESSOR(X) X+1
#define INCREMENT(X) X = SUCCESSOR(X)
void main()
{
int value = 5;
INCREMENT(value);
}
in other order:
#include "file2.h"
#include "file1.h"
void main()
{
int value = 5;
INCREMENT(value);
}
yourcode.cpp
#define INCREMENT(X) X = SUCCESSOR(X) // <-
#define SUCCESSOR(X) X+1
void main()
{
int value = 5;
INCREMENT(value);
}
but you can do it also in this way:
#include "file1.h"
#define INCREMENT(X) X = SUCCESSOR(X)
in this case you have to prevent the compiler to include the symbols twice.
#include "file1.h"
#include "file2.h"
void main()
{
int value = 5;
INCREMENT(value);
}
yourcode.cpp
#define SUCCESSOR(X) X+1
#define SUCCESSOR(X) X+1 // <- compiler throws a redefined symbol error
#define INCREMENT(X) X = SUCCESSOR(X)
void main()
{
int value = 5;
INCREMENT(value);
}
how to prevent that?
#ifndef __FILE1_H_INCLUDED
#define __FILE1_H_INCLUDED
#define SUCCESSOR(X) X+1
#endif // __FILE1_H_INCLUDED
in your code
#ifndef __FILE1_H_INCLUDED
#define __FILE1_H_INCLUDED
#define SUCCESSOR(X) X+1
#endif // __FILE1_H_INCLUDED
#ifndef __FILE1_H_INCLUDED // <- compiler ignores code inside this section
#define __FILE1_H_INCLUDED
#define SUCCESSOR(X) X+1
#endif // __FILE1_H_INCLUDED
#define INCREMENT(X) X = SUCCESSOR(X)
void main()
{
int value = 5;
INCREMENT(value);
}
Regards.