J
Johs32
I have the follwing code:
#include <stdio.h>
#include <stdlib.h>
struct data {
int *ip;
};
struct data first;
struct data *current = &first;
int init()
{
int a = 222;
current->ip = &a;
printf("init :%d\n", *current->ip);
return 0;
}
void zap(int a, int b)
{
printf("current->prio: %d\n",*current->ip);
}
int main()
{
init();
zap(3,5);
return 0;
}
When I do the printf in init() I get 222 as expected. But when I do it in
zap(int a, int b) I get 5!! If I remove the arguments from zap like this:
zap()
and call it like this from main:
zap()
I get 222 printed as expected from the zap() function.
What kind of black magic is this?
JOhs
#include <stdio.h>
#include <stdlib.h>
struct data {
int *ip;
};
struct data first;
struct data *current = &first;
int init()
{
int a = 222;
current->ip = &a;
printf("init :%d\n", *current->ip);
return 0;
}
void zap(int a, int b)
{
printf("current->prio: %d\n",*current->ip);
}
int main()
{
init();
zap(3,5);
return 0;
}
When I do the printf in init() I get 222 as expected. But when I do it in
zap(int a, int b) I get 5!! If I remove the arguments from zap like this:
zap()
and call it like this from main:
zap()
I get 222 printed as expected from the zap() function.
What kind of black magic is this?
JOhs