: Inclusion guards or not, you will still get multiple definition errors if you have anything more than the function prototypes in the header files, and include them more than once.
: :
:
Did you try to prove that statement with the code and if you have that code - can I see it?
:
Absolutely. Make a new Win32 console app project, and add 3 files to the project, "main.c", "scrap.c", and "scrap.h". In "main.c", add this:
#include <stdio.h>
#include "scrap.h"
int main()
{
printf("answer is %d\n", GetAnswer());
PrintAnswer();
return 0;
}
Now in "scrap.c" add this:
#include <stdio.h>
#include "scrap.h"
void PrintAnswer(void)
{
printf("answer is %d\n", GetAnswer());
return;
}
Last file, "scrap.h", add this:
#ifndef SCRAP_H_
#define SCRAP_H_
void PrintAnswer(void);
int GetAnswer(void);
int GetAnswer(void)
{
return 100;
}
#endif // SCRAP_H_
Notice that you will get these errors :
main.c
scrap.c
Linking...
scrap.obj : error LNK2005: _GetAnswer already defined in main.obj
Debug/Scrap.exe : fatal error LNK1169: one or more multiply defined symbols found
Error executing link.exe.
Scrap.exe - 2 error(s), 0 warning(s)
Now, try it again, removing the line #include "scrap.h" from the file "scrap.c"... no more errors.
Programming is like kids... One mistake and you have to support it for life