Thursday, June 12, 2008

variable type checking in C

Put all the files in a directory. Run gcc *.c -o main.exe. The compilation will succeed. The reason is that C does not check type consistency of external variable declaration and reference.
1 one.c

int abc = 1;

2 main.c

#include <stdio.h>
extern float abc;
int main(void) {
printf( "%f", abc );
}

No comments: