The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > High Level Programming
.
google unix.com



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

 
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #1 (permalink)  
Old 07-24-2008
Tanvirk Tanvirk is offline
Registered User
  
 

Join Date: Jan 2008
Posts: 8
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
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 06:34 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0