March 20th, 2013, 01:00 AM
I have two files file1.c and file2.c both have common global variable as int a;..Now when I include them both in my file then compiler considers only the first one...This is due to tentative definitions in c..But i have heard to avoid this you can use extern in one of the variables..Can someone please explain how can this help??
March 20th, 2013, 02:53 AM
March 20th, 2013, 09:22 AM
In the header file, declare that variable as extern. That will inform every source file that #include's that header about the existence of that variable but without actually creating it. Then in one and only one of the source files, actually declare that variable.
That's all it takes.
Just a minute ... Just a minute ...
Are you including source files into another source file? Ie, is this what you're doing?
Originally Posted by ghost_rider
If that is what you're doing, then stop that idiocy right now! Use proper procedures for multiple file projects and only #include header files.
Comments on this post