The following code:
#include<stdlib.h>
#include<stdio.h>
int main (void) {
FILE** f;
if ( (*f = (FILE *)malloc( sizeof(FILE *)) ) == NULL) {
printf("Out of RAM or some other disaster!\n");
return 1;
}
printf("OK!\n");
return 0;
}
compiles and runs without complaint on Mac OS X 10.8. However on Windows 7 (compiling with MinGW) it crashes on the malloc(). Why would this be and or any ideas to stop it happening?
Thanks!
Note: This was obviously originally part of a larger program but I've reduced the entire program to the above and tried just this code on both the Mac and PC and have replicated the behaviour.
if
. You close one less than you open there.