![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Sed variable substitution when variable constructed of a directory path | alrinno | Shell Programming and Scripting | 2 | 07-11-2008 03:24 PM |
| Enviornment Variable in B shell (I call it nested variable) | princelinux | Shell Programming and Scripting | 4 | 07-02-2008 02:35 AM |
| passing a variable inside a variable to a function | KingVikram | UNIX for Dummies Questions & Answers | 2 | 01-14-2008 08:28 PM |
| extern for functions | naan | High Level Programming | 8 | 07-06-2007 05:57 PM |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
Extern variable.
file1.c Code:
int a1;
int main()
{
a1 = 2;
printf("\na1 = %d\n", a1);
next();
printf("\na1 = %d\n", a1);
next1();
printf("\na1 = %d\n", a1);
}
file2.c Code:
#include <stdio.h>
int b1 = 0;
void next(void)
{
char a1;
a1 = 'a';
b1 = 77;
}
file3.c Code:
int a1;
void next1(void)
{
float b1;
b1 = 20.3;
a1 = 15;
}
When i compile it using gcc -c and create separate respective object file -and try to link them it dosent give any errors as to "multiple declaration of variable" as of "variable a" in this case. -And it gets comiled and linked successfully. -also the "third printf" in file1.c prints the value of a=15 which is updated by file3.c. -whereas its nowhere specified in file3.c that variable "a is an exterm variable" in that case file1.c would printf the value of a1=15; -so.................??????????????????????? Regards Tanvir Moved to High Level Programming Forum. FPMurphy Last edited by vino; 07-24-2008 at 06:36 AM.. Reason: added code tags |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|