D
David Beers
I thought I understood C well enough, but this one has really taken me
by surprise.
I call a function that has several arguments. The function definition
happens to be in a different file (which I didn't think made a
difference). I can look at the value of the variables being passed
immediately before the function call and immediately after the
function begins to execute using my debugger. And the values
*change*.
Is there some strange scope rule that has eluded me so far in my C
programming? Is the stack being corrupted somehow? I'm at a loss.
My code is something like this (simplified, but honest to gosh, not
that much):
/* first.c */
void callingFunc()
{
int foo = 1;
int bar = 0;
int slug = 6000;
if (myFunc(foo, bar, &slug)) {
// do something
}
}
/* second.c */
int myFunc(int foo, int bar, int *slug)
{
long blah = 0;
// foo == 0 and bar == 44551 now!
// the address of slug is passed just fine, though
}
Any idea what could be happening here? (BTW, I'm programming on the
Palm OS, if this makes any difference.)
David
by surprise.
I call a function that has several arguments. The function definition
happens to be in a different file (which I didn't think made a
difference). I can look at the value of the variables being passed
immediately before the function call and immediately after the
function begins to execute using my debugger. And the values
*change*.
Is there some strange scope rule that has eluded me so far in my C
programming? Is the stack being corrupted somehow? I'm at a loss.
My code is something like this (simplified, but honest to gosh, not
that much):
/* first.c */
void callingFunc()
{
int foo = 1;
int bar = 0;
int slug = 6000;
if (myFunc(foo, bar, &slug)) {
// do something
}
}
/* second.c */
int myFunc(int foo, int bar, int *slug)
{
long blah = 0;
// foo == 0 and bar == 44551 now!
// the address of slug is passed just fine, though
}
Any idea what could be happening here? (BTW, I'm programming on the
Palm OS, if this makes any difference.)
David