473,569 Members | 2,879 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 4890
ravi_shankar <me*********@db forums.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**********@d aimlerchrysler. 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**********@d aimlerchrysler. com> wrote in message news:be******** **@news.sns-felb.debis.de.. .
ravi_shankar <me*********@db forums.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******@hanma il.net)
Dept. of Physics, Univ. of Seoul

Nov 13 '05 #3
In 'comp.lang.c', ravi_shankar <me*********@db forums.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**********@no os.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.c om> ravi_shankar <me*********@db forums.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*********@db forums.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.c om/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
2583
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. Two of the globals are pointers which are initialized at runtime. The others are classes whose values are initialized in the global space. When I...
12
2701
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 linkage? Not much on this in the FAQ or tutorials.
19
3830
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 storage-class specifier. My (little) C experience tells me that an object with "extern" is to let the linker knows that the object is referencing the...
29
448
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() { f(); }
5
16596
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 extern storage class: /****************************************************************** SOURCE FILE ONE...
17
4910
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
2846
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
2173
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
6394
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 <http://www.cpax.org.uk/prg/portable/c/resources.php>), I came across the following declaration: extern char *const (*goop( char *b ))( int, long ); which is explained as:
0
7703
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7930
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8138
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7983
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6290
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5514
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3651
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2118
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1229
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.