Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c.moderated > #521

Re: why do some writers declare and define variables separately

From Hans-Bernhard Bröker <HBBroeker@t-online.de>
Newsgroups comp.lang.c.moderated
Subject Re: why do some writers declare and define variables separately
Date 2013-10-25 19:36 -0500
Organization Usenet Fact Police
Message-ID <clcm-20131025-0001@plethora.net> (permalink)
References <clcm-20130918-0002@plethora.net> <clcm-20131003-0002@plethora.net> <clcm-20131008-0006@plethora.net> <clcm-20131022-0001@plethora.net> <clcm-20131024-0002@plethora.net>

Show all headers | View raw


On 25.10.2013 03:10, Francis Glassborow wrote:

> int i;
>
> Defines an uninitialised int (i.e. assigns storage for an int value but
> does not initialise it) and then binds the name i to that storage.

Actually that's only one of four things the above line can mean.

The above is correct only if that line appears inside a statement block. 
  In that case it defines an automatic, block-scoped, un-initializaed 
variable.

If that line appears inside a struct or union type declaration, it 
declares an element of said struct or union type.

If the same line appears outside any block, it can do one of two things:

a) it can define a variable of static duration and external linkage, 
with implied initialization to zero, or
b) it can act the same as if you had written "extern int i;", i.e. be a 
pure declaration.

The distinction between a) and b) is ruled by the somewhat complicated 
concept of a "tentative definition".
-- 
comp.lang.c.moderated - moderation address: clcm@plethora.net -- you must
have an appropriate newsgroups line in your header for your mail to be seen,
or the newsgroup name in square brackets in the subject line.  Sorry.

Back to comp.lang.c.moderated | Previous | NextPrevious in thread | Find similar | Unroll thread


Thread

why do some writers declare and define variables separately yoodavid <odimegwudavid@yahoo.fr> - 2013-09-18 16:42 -0500
  Re: why do some writers declare and define variables separately mt <mahdert@gmail.com> - 2013-10-03 13:37 -0500
    Re: why do some writers declare and define variables separately James Kuyper <jameskuyper@verizon.net> - 2013-10-08 16:38 -0500
      Re: why do some writers declare and define variables separately ThosRTanner <ttanner2@bloomberg.net> - 2013-10-22 16:36 -0500
        Re: why do some writers declare and define variables separately Jens Schmidt <Jens.Schmidt-HH@gmx.de> - 2013-10-24 20:10 -0500
        Re: why do some writers declare and define variables separately Francis Glassborow <francis.glassborow@btinternet.com> - 2013-10-24 20:10 -0500
          Re: why do some writers declare and define variables separately Hans-Bernhard Bröker <HBBroeker@t-online.de> - 2013-10-25 19:36 -0500

csiph-web