D
David Jackson
I'm having a weird problem where a function gets a different value of a
pointer than what was passed to it. I haven't been able to make a small
example that duplicates the error but here's an example to show what I mean:
#include <stdio.h>
void f(int * p);
int main(void) {
int x;
int * px = &x;
x = 23;
printf("px=%p\n", px);
f(px);
return 0;
}
void f(int * p) {
printf("p=%p\n", p);
}
So if this example would behave the way my program does, when I pass a
pointer to a function like this it prints out a different address in the
printf statement inside the function, so somehow the function recieves a
different value than what was passed to it! There are no statements
between the printf in the main function and the program is not
multithreaded so its not a case of the pointer being overwritten
somewhere in between. Does anybody have any idea what could cause this
to happen? This is probably a stupid mistake on my part but I'm really
stuck so if anybody has a suggestion please tell me.
If it makes any difference, in my program the function f is in a
different file.
pointer than what was passed to it. I haven't been able to make a small
example that duplicates the error but here's an example to show what I mean:
#include <stdio.h>
void f(int * p);
int main(void) {
int x;
int * px = &x;
x = 23;
printf("px=%p\n", px);
f(px);
return 0;
}
void f(int * p) {
printf("p=%p\n", p);
}
So if this example would behave the way my program does, when I pass a
pointer to a function like this it prints out a different address in the
printf statement inside the function, so somehow the function recieves a
different value than what was passed to it! There are no statements
between the printf in the main function and the program is not
multithreaded so its not a case of the pointer being overwritten
somewhere in between. Does anybody have any idea what could cause this
to happen? This is probably a stupid mistake on my part but I'm really
stuck so if anybody has a suggestion please tell me.
If it makes any difference, in my program the function f is in a
different file.