473,323 Members | 1,574 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,323 software developers and data experts.

extern storage class specifier for variables


hi all.
what's the advantage of prefixing a varible with "extern" storage class
specifier other than its default initializion .
you can mail to me :
ra****************@rediffmail.com

--
Posted via http://dbforums.com
Nov 13 '05 #1
6 4876
ravi_shankar <me*********@dbforums.com> wrote:

hi all.
what's the advantage of prefixing a varible with "extern" storage class
specifier other than its default initializion .
The extern specifier doesn't make the variabel initialize. All variables
with file scope (that is all that are not within block scope) are
initialized to 0 if there is no explicit initialization.

Extern tells the compiler that you are not defining the variable here,
but rather declaring that this variable exists somewhere else in another
translation unit and you are referring to that.
you can mail to me :
ra****************@rediffmail.com


You post here, you read here.

--
Z (Zo**********@daimlerchrysler.com)
"LISP is worth learning for the profound enlightenment experience
you will have when you finally get it; that experience will make you
a better programmer for the rest of your days." -- Eric S. Raymond
Nov 13 '05 #2

"Zoran Cutura" <zo**********@daimlerchrysler.com> wrote in message news:be**********@news.sns-felb.debis.de...
ravi_shankar <me*********@dbforums.com> wrote: [...]
Extern tells the compiler that you are not defining the variable here,
but rather declaring that this variable exists somewhere else in another
translation unit and you are referring to that.


Provided that the (file scope) declaration has no initializer; but
it's very bad to provide both of "extern" and an initializer to a
file scope declaration.
--
Jun, Woong (my******@hanmail.net)
Dept. of Physics, Univ. of Seoul

Nov 13 '05 #3
In 'comp.lang.c', ravi_shankar <me*********@dbforums.com> wrote:
what's the advantage of prefixing a varible with "extern" storage class
specifier other than its default initializion .


It's ignored when you define the variable, but it allows a separated
declaration of this variable when you want it to be shared in different
modules.

1 - Are you sure you need a global scope variable?
2 - If so, define it in a source file (say data.c)
3 - Declare it in a header (say data.h>
4 - For consitency, include this header in th definition file (data.c) and
all the files that need a reference to this variable.
5 - For readability and maintenance, I suggest that the global scope
variables are prefixed with G_

/* data.h */
#ifndef H_DATA
#define H_DATA
extern int G_myglobal;
extern int G_myarray[123];
#endif

/* data.c */
#include "data.h"

int G_myglobal;
int G_myarray[];

--
-ed- em**********@noos.fr [remove YOURBRA before answering me]
The C-language FAQ: http://www.eskimo.com/~scs/C-faq/top.html
<blank line>
FAQ de f.c.l.c : http://www.isty-info.uvsq.fr/~rumeau/fclc/
Nov 13 '05 #4
ravi_shankar wrote:
hi all.
what's the advantage of prefixing a varible with "extern" storage class
specifier other than its default initializion .
Prefixing a variable declaration with `extern' says: "This variable is
defined in another compilation unit." Nothing more, nothing less.
you can mail to me :
ra****************@rediffmail.com

Post here. Read here.

HTH,
--ag
--
Artie Gold -- Austin, Texas

----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption =---
Nov 13 '05 #5
In <30****************@dbforums.com> ravi_shankar <me*********@dbforums.com> writes:

what's the advantage of prefixing a varible with "extern" storage class
specifier other than its default initializion .


Without extern, the declaration becomes a definition (in the absence
of another definition for that identifier, in that file).

With extern, the declaration remains a declaration.

Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de
Nov 13 '05 #6
On Fri, 04 Jul 2003 11:43:39 +0000, in comp.lang.c , ravi_shankar
<me*********@dbforums.com> wrote:

hi all.
what's the advantage of prefixing a varible with "extern" storage class
specifier other than its default initializion .
sounds like a homework question...
Anyway, an extern variable is one that is defined elsewhere.
you can mail to me :
ra****************@rediffmail.com


post here, read here.

--
Mark McIntyre
CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
CLC readme: <http://www.angelfire.com/ms3/bchambless0/welcome_to_clc.html>
----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption =---
Nov 13 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: John Ratliff | last post by:
I have a few global variables in my app. They are defined in the main application class file and declared (extern) in a header which can be included by anyone who would want to use these variables....
12
by: G Patel | last post by:
I've seen some code with extern modifiers in front of variables declared inside blocks. Are these purely definitions (no definition) or are they definitions with static duration but external...
19
by: ccwork | last post by:
Hi all, I am reading "C: A Reference Manual" 4th ed and I get lost for the "extern". It says that global object without specifying the storage-class specifier will have "extern" as the default...
29
by: DevarajA | last post by:
Can anyone explain me what extern is used for? I thought it was used to declare variables definited in other files, but i can do that also without extern. /*file a.c*/ int a=5; int main() {...
5
by: siliconwafer | last post by:
Hi all, I wanted to know that is use of extern keyword mandatory in case of global variables and functions used in other source files? i.e consider a following piece of code from MSDN explaining...
17
by: Tapeesh | last post by:
I would like to know what is the expected behaviour of C compilers when an extern decleration is intialized. When the following code is compiled using gcc //File extern.c int arr ; int a ;
5
by: Christian Christmann | last post by:
Hi, I've tree questions on the storage class specifier "extern": 1) Code example: int main( void ) { int b = -2; // my line 3 if ( a ) {
7
by: Christian Christmann | last post by:
Hi, I've a a question on the specifier extern. Code example: void func( void ) { extern int e; //...
3
by: coder | last post by:
While reading the page on "Reading C Declarations" <http://www.ericgiguere.com/articles/reading-c-declarations.html> (recommended by Mr. Heathfield at...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.