Article View: comp.lang.c.moderated
Article #2203Re: "extern" and function declarations
From: Tanmoy Bhattacharya
Date: Fri, 08 Mar 1996 23:02
Date: Fri, 08 Mar 1996 23:02
61 lines
3143 bytes
3143 bytes
In article <4hmslc$b35@solutions.solon.com> thomas@eel.rdc.toshiba.co.jp (Arun M. Thomas) writes: AMT: With respect to the first line in this paragraph then, how does one declare AMT: a variable without also defining it? A statement like: AMT: AMT: int i; AMT: AMT: both declares and creates a tentative definition of the variable if I am AMT: understanding correctly. (I can't think of a case in which it will actually be AMT: necessary to declare without defining a variable, but I'm asking to find out if AMT: it is possible. If there is a situation in which it would be useful to declare AMT: without defining, I would appreciate an example.) AMT: AMT: >From the discussion preceding the section included above, I gathered that AMT: within a function, a statement like the above (i.e. "int i;") is in fact a AMT: bare declaration, with no default value assigned to it. If this understanding AMT: is incorrect, please let me know :) I suspect your basic problem is that you think `define a variable' means `giving this variable a value'. This was not the sense in which it was being used in this thread so far. In this thread, people were trying to distinguish two different types of declaration: one that just informs that the variable has been `created' somewhere (with or without initialization), and the other instructs the compiler to create the variable. It is this latter kind of declaration which is called `definition'. So, if you write `extern int i;' in any context whatsoever, i is declared but not defined. It tells the compiler that a static duration variable i exists. (It turns out that such a variable cannot be uninitialized.) Note that `extern int i;' itself does not create the object. `extern int i = 12;' is a definition. It creates i and initializes it to 12. (This declaration is invalid inside a block.) `int i;' inside a block is a definition. It however does not initialize the object. `int i;' at file scope is a tentative definition, which in itself doesn't reserve space: but guarantees that space will be reserved (and initialized) in the translation unit. Cheers Tanmoy -- tanmoy@qcd.lanl.gov(128.165.23.46) DECNET: BETA::"tanmoy@lanl.gov"(1.218=1242) Tanmoy Bhattacharya O:T-8(MS B285)LANL,NM87545 H:#9,3000,Trinity Drive,NM87544 Others see <gopher://yaleinfo.yale.edu:7700/00/Internet-People/internet-mail>, <http://alpha.acast.nova.edu/cgi-bin/inmgq.pl>or<ftp://csd4.csd.uwm.edu/pub/ internetwork-mail-guide>. -- <http://nqcd.lanl.gov/people/tanmoy/tanmoy.html> fax: 1 (505) 665 3003 voice: 1 (505) 665 4733 [ Home: 1 (505) 662 5596 ]
Technical Details
Message-ID:
<4hqe9s$1h5@solutions.solon.com>Path:
arc1-ca.pugleaf.net!solon.com!not-for-mailReferences:
<4hlael$4ed@solutions.solon.com> <4hmslc$b35@solutions.solon.com>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!solon.com!not-for-mail From: tanmoy@qcd.Lanl.GOV (Tanmoy Bhattacharya) Newsgroups: comp.lang.c.moderated Subject: Re: "extern" and function declarations Date: 8 Mar 1996 17:02:20 -0600 Organization: Los Alamos National Laboratory Sender: clc@solutions.solon.com Approved: clc@solutions.solon.com Message-ID: <4hqe9s$1h5@solutions.solon.com> References: <4hlael$4ed@solutions.solon.com> <4hmslc$b35@solutions.solon.com> NNTP-Posting-Host: solutions.solon.com