M
Mark
Hello,
Consider the following simple code.
#include <stdio.h>
static void p2(int *pp)
{
printf("%s: pp=%d @ %p\n", "p2", *pp, (void *)pp);
}
static int p1(void)
{
int p=10;
printf("p1: p=%d @ %p\n", p, (void *)&p);
p2(&p);
return 0;
}
int main(void)
{
p1();
return 0;
}
Is it guaranteed that object 'p' defined in function p1 will have the same
value and will be at the same address location, when it is used from
function p2 ? I know that the C standard doesn't operate such terms as
stack or heap, but as far as I understand most of the time automatic
variables (automatic -- local?) will be placed on the stack, and my question
is - is it safe to pass parameters this way? (I do not intend to *store*
anything at the locations of these parameters, only pass information and use
it once).
Thanks in advance.
Mark
Consider the following simple code.
#include <stdio.h>
static void p2(int *pp)
{
printf("%s: pp=%d @ %p\n", "p2", *pp, (void *)pp);
}
static int p1(void)
{
int p=10;
printf("p1: p=%d @ %p\n", p, (void *)&p);
p2(&p);
return 0;
}
int main(void)
{
p1();
return 0;
}
Is it guaranteed that object 'p' defined in function p1 will have the same
value and will be at the same address location, when it is used from
function p2 ? I know that the C standard doesn't operate such terms as
stack or heap, but as far as I understand most of the time automatic
variables (automatic -- local?) will be placed on the stack, and my question
is - is it safe to pass parameters this way? (I do not intend to *store*
anything at the locations of these parameters, only pass information and use
it once).
Thanks in advance.
Mark