>If you declare a variable in  A.c file, and in B.c
>file (which is going to be part of the executable),
>you try to access that variable, your attempt will
>fail (compiler will give an error) unless you declare
that 
>variable as extern in B.c. Of course if you include
the >declaration in A.H and include A.h in both A.c
and B.c >you will succeed. So, extern type is
mandatory 
>where you are using a variable which is declared in a
>different scope. If you just declare a variable as
>extern but don't have the actual definition in one of
>the files in the excutable, the linker will throw an
>error.

Yeah u r correct only...
but, please try it practically...
its not giving any error ....
its same with & without extern type declaration..

please execute  the attached file...
i had declared a variable "int i" in t1.c  file..
and included in t2.c and im able to accessing the
variable "i"  with & without the declaration of
 "extern int i" in t2.c file....

Please execute and see whether i did telling  correct 
or not.... 
i had executed in Linux(gcc compiler)

Rgds
Madhukar

________________________________________________________________________
Yahoo! India Matrimony: Find your life partner online
Go to: http://yahoo.shaadi.com/india-matrimony

------------------------ Yahoo! Groups Sponsor --------------------~--> 
$4.98 domain names from Yahoo!. Register anything.
http://us.click.yahoo.com/Q7_YsB/neXJAA/yQLSAA/EbFolB/TM
--------------------------------------------------------------------~-> 

To unsubscribe : [EMAIL PROTECTED]

 
Yahoo! Groups Links

<*> To reply to this message, go to:
    
http://groups.yahoo.com/group/Programmers-Town/post?act=reply&messageNum=4864
    Please do not reply to this message via email. More information here:
    http://help.yahoo.com/help/us/groups/messages/messages-23.html

<*> To visit your group on the web, go to:  
    http://groups.yahoo.com/group/Programmers-Town/

<*> To unsubscribe from this group, send an email to:
    [EMAIL PROTECTED]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 
int i;
fun()
{
i=10;
printf("fun: i:%d\n",i);
}
#include <stdio.h>
#include "t1.c"
extern  int i; /* try with and with out this  type declaration */

main()
{
fun();
printf("main: i:%d\n",i);
}

Reply via email to