F
FMorales
-- I didn't notice anything about this specifically
-- in the c.l.c. FAQ, nor could i get a strait answere
-- from my copy of the C standard. Hopeing someone
-- here could shed some light on it ...
6.2.1
"If the declarator or type specifier that declares
the identifier appears inside a block or within the
list of parameter declarations in a function definition,
the identifier has block scope, which terminates at the
end of the associated block."
I believe this talks about what we learned early on :
int main(void)
{
{
int a;
}
printf("%d\n", a); /* ERROR - Invalid */
return 0;
}
Once outside of the closing } a is no longer accessible.
It's out of our current "scope". Which brings me to my
question. Since that data is static, is it automatically
allocated at program start up?
int main(void)
{
int i;
return 0;
}
As "i" would be in this example ? What if there's a conditional
statement there ? As in :
int main(void)
{
int i = 0;
if(!i) {
int a;
}
return 0;
}
If "a" is /NOT/ automatically allocated with "i", what is
the compiler doing to make sure it gets allocated only when,
and if it's ever needed (like if "i" changes before the
"if", or if it waits for input from a user which we'll assume
is unknown untill runtime will "a" still get allocated ?)
Any help is greatly appreciated, just something i started
wondering about FMorales...
-- in the c.l.c. FAQ, nor could i get a strait answere
-- from my copy of the C standard. Hopeing someone
-- here could shed some light on it ...
6.2.1
"If the declarator or type specifier that declares
the identifier appears inside a block or within the
list of parameter declarations in a function definition,
the identifier has block scope, which terminates at the
end of the associated block."
I believe this talks about what we learned early on :
int main(void)
{
{
int a;
}
printf("%d\n", a); /* ERROR - Invalid */
return 0;
}
Once outside of the closing } a is no longer accessible.
It's out of our current "scope". Which brings me to my
question. Since that data is static, is it automatically
allocated at program start up?
int main(void)
{
int i;
return 0;
}
As "i" would be in this example ? What if there's a conditional
statement there ? As in :
int main(void)
{
int i = 0;
if(!i) {
int a;
}
return 0;
}
If "a" is /NOT/ automatically allocated with "i", what is
the compiler doing to make sure it gets allocated only when,
and if it's ever needed (like if "i" changes before the
"if", or if it waits for input from a user which we'll assume
is unknown untill runtime will "a" still get allocated ?)
Any help is greatly appreciated, just something i started
wondering about FMorales...