M
mailtogops
Hi All,
This is very basic C/C++ question but I need internals of C/C++ how the
langauge/compiler do this..
Say I have two header files
1. header1.h
2. header2.h
Here the code for header1.h
Header1.h
---------------
int g_header1 = 10;
void print1()
{
printf("%d",g_header1);
}
Here the code for header2.h
Header2.h
----------------
int g_header2 = 10;
void print2()
{
printf("%d",g_header1);
}
Now I have two C/CPP source files
They are
1. Source1.C/CPP
2. Source2.C/CPP
Source1.C/CPP code
#include <header1.h>
#include <header2.h>
void Disp()
{
g_header1 = 400;
g_header2= 300;
print1();
print2();
}
Source2.C/CPP code
#include <header1.h>
#include <header2.h>
void DispResult()
{
g_header1 = 1000;
g_header2= 2000;
print1();
print2();
}
Here assumption is all the four files are in the same project
My Question
1. Internally, during compilation of the code, what the compiler does?
2. How many instances of g_header1, g_header2 would be there?
I would appreciate if anyone clear my long time uncleared question..
Thanks & Regards,
Gopal
This is very basic C/C++ question but I need internals of C/C++ how the
langauge/compiler do this..
Say I have two header files
1. header1.h
2. header2.h
Here the code for header1.h
Header1.h
---------------
int g_header1 = 10;
void print1()
{
printf("%d",g_header1);
}
Here the code for header2.h
Header2.h
----------------
int g_header2 = 10;
void print2()
{
printf("%d",g_header1);
}
Now I have two C/CPP source files
They are
1. Source1.C/CPP
2. Source2.C/CPP
Source1.C/CPP code
#include <header1.h>
#include <header2.h>
void Disp()
{
g_header1 = 400;
g_header2= 300;
print1();
print2();
}
Source2.C/CPP code
#include <header1.h>
#include <header2.h>
void DispResult()
{
g_header1 = 1000;
g_header2= 2000;
print1();
print2();
}
Here assumption is all the four files are in the same project
My Question
1. Internally, during compilation of the code, what the compiler does?
2. How many instances of g_header1, g_header2 would be there?
I would appreciate if anyone clear my long time uncleared question..
Thanks & Regards,
Gopal