There are three files - mainfile.c, helper.c and helper.h. in the same directory. helper.h contains function prototypes of foo1
and foo2
, a struct
declaration and some typedefs
.
header.h
is included in both helper.c
and in mainfile.c
(helper.h
also has include guards, so double declarations aren't a problem.). The functions foo1
and foo2
are defined in helper.c
If I include helper.h
in any .c
file, my understanding is that the contents of helper.h
are literally pasted (word for word) in the .c
file at run time. Is my understanding correct?
I used to think that if I call foo1
in mainfile.c
the control transfers to the start of foo1
, and that foo1
can't interact with anything else defined in helper.c
. But there is something wrong with that line of thinking because when I declare a global variable in helper.c
, both functions are able to access it. So what does happen when mainfile.c
calls foo1
or foo2
?
My understanding of the static storage class is that it converts a local variable into a global variable, as all the functions are able to access it. So if I declare a static array in foo1 and then call foo2
in mainfile.c
, will foo2
be able to access this static array?
The content of dictionary.c should be something like this
void foo1 (void)
{
static int array[10] = {1,2,3,4,5,6,7,8,9,10}
//more code
}
void foo2 (void)
{
array[7] = 4;
// more code
}
When foo2 is called from mainfile , will it be able to access the static array.