Hi, u can only extern glob variables and not local ---------- Sent from my Nokia Phone
------Original message------ From: Nikku Kumar <[email protected]> To: <[email protected]> Date: Tuesday, January 24, 2012 12:11:56 AM GMT+0530 Subject: [gcj] unpredicted behavior of extern I tried extern in two different cases and its giving different result CASE 1: in file test1.c ***************** #include<stdlib.h> void fun(void); int *ptr; int main() { ptr = (int *) malloc(100*sizeof(int)); fun(); return 0; } in file test2.c *************** #include<stdio.h> extern int ptr[]; void fun(void) { ptr[5] = 5; printf("%d\n",ptr[5]); } on compiling both file (test1.c and test2.c) together it is working fine here the extern declaration does not gives any error during linking ******************************************************************************** CASE 2: in file test3.c ***************** #include<stdio.h> #include<stdlib.h> int *ptr; void fun(void); int main() { ptr = (int *) malloc(100 * sizeof(int)); fun(); return 0; } void fun(void) { extern int ptr[]; ptr[5] = 100; printf("%d\n",ptr[5]); } but while compiling file test3.c it is giving error (conflicting types for ‘arr’) Can anyone please explain me the logic behind this behavior Thanks, Nikku Kumar -- You received this message because you are subscribed to the Google Groups "Google Code Jam" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/google-code?hl=en. -- You received this message because you are subscribed to the Google Groups "Google Code Jam" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/google-code?hl=en.
