Hi All
I have a main file (main.c) which includes show.h and show1.h
But show1.c also includes show.h. show.h looks like
Because it is included twice I was expecting compile errors, but the program compiles/runs fine, why ?Code:void init() ; void show() ; void set(int x) ; int *get() ; extern int *y ;
I thought, in this situation, I needed things like #ifndef .... #endif!
Below are the listings of all the files
main.c
show.cCode:#include "show.h" #include "show1.h" int main(int argc, char *argv[]) { init() ; set(10) ; show() ; set(20) ; show() ; // ------- show1() ; set(303) ; show1() ; return 0 ; }
show.h (see above)Code:#include <stdlib.h> // malloc #include <stdio.h> // printf #include "show.h" int *y ; void init() { y = malloc(sizeof(int)) ; } void set(int x) { *y = x ; } int * get() { return y ; } void show() { printf("value is %d\n", *y) ; }
show1.c
show1.hCode:#include <stdio.h> // printf #include "show.h" extern int* y ; void show1() { printf("the value is %d\n", *y) ; show(); }
Code:void show1() ;



LinkBack URL
About LinkBacks


