We're getting some funny behavior in the Visual Studio debugger with the following. I'm not sure if it's the code or some debugger weirdness (seen stuff like it before). We are trying to return a pointer to an value in an array.
The weird behavior is that the value of x changes to equal y after func() is called a second time...at least, that's what it appears in the debugger.
I suppose my question is, is this even legal/safe?
The pointers should be on the heap in main()'s scope right, so it should be fine?
char stuff[100];
char * func()
{
// i is random in the range
stuff[i] = 'a';
return &stuff[i];
}
main()
{
char * x = func();
char * y = func();
}