variables changing when passed to function

I've made a few projects recently where I pass an int to a function by value and then once inside the function the variable has some ridiculous value up in the thousands, every time this has happened I've made a new project and imported the exact same source and header files into it, and the problem has fixed itself. What could cause variables to morph?
Can you post an example of that?
Are you saying that you have code where you do this:

1
2
3
4
5
6
7
8
9
10
void bar(int y)
{
    cout << y << endl;
}
void foo()
{
    int x = 1;
    cout << x << endl;
    bar(x);
}


And your code will outputs something like this?
1
33249802


The easiest answer is that your stack is hosed up. Does your code compile cleanly with verbose warnings turned on?
Last edited on
Yes that's exactly what happens, and yeah it compiles cleanly, I only get a few warnings about int to float conversions with warnings at level 4. The stack being filled up would make sense though as I'm doing a minimax search at a depth of 7, that's a lot of function calls piled up on there.
Last edited on
Topic archived. No new replies allowed.