I just discovered a bug where the code looked something like this:
char *foo = malloc(SOME_NUM * sizeof(char));
if (!processReturnsTrueOrFalse(foo)) {
free(foo);
char *foo = malloc(SOME_NUM * sizeof(char));
// More stuff, whatever
}
This compiles, but it's weird that I am allowed to define two variables within the same function, but the compiler appears to scope them differently.
If this were the case, how do I differentiate the inner foo with the outer one? How did the compiler know that in the free before my second declaration, I was trying to free the outer foo, but then when I redeclared the inner foo, it didn't give me an error?
Thanks for any info. This is probably a pretty obvious, newbie question.