Suppose that I have those three files:
a.h
//a.h header
#include <stdio.h>
int int_variable;
void a_f()
{
printf("int_variable: %d\n", int_variable)
int_variable++;
}
b.h
//b.h header
#include <stdio.h>
int int_variable;
void b_f()
{
printf("int_variable: %d\n", int_variable)
int_variable++;
}
main.c
//main.c
#include "a.h"
#include "b.h"
int main()
{
a_f();
b_f();
return 0;
}
Why compiling in C++ generates redefinition error, but in C doesn't? I am C++ developer, then in C++ makes sense to me, but why in C this is not an error?
When I executed the C generated code, the output was:
int variable: 0
int variable: 1
Thanks