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


Groups > comp.lang.c > #36730

Re: why do some writers declare and define variables separately

From Ian Collins <ian-news@hotmail.com>
Newsgroups comp.lang.c
Subject Re: why do some writers declare and define variables separately
Date 2013-09-26 09:17 +1200
Message-ID <bah27qFkslhU4@mid.individual.net> (permalink)
References (1 earlier) <kOqdnSun1P-cJt_PnZ2dnUVZ_vidnZ2d@posted.internetamerica> <bafsk8FkslhU2@mid.individual.net> <l1ulhq$2lp$1@dont-email.me> <bagu1qFkslhU3@mid.individual.net> <524349BA.1090100@verizon.net>

Show all headers | View raw


James Kuyper wrote:
> On 09/25/2013 04:06 PM, Ian Collins wrote:
>> James Kuyper wrote:
>>> On 09/25/2013 06:35 AM, Ian Collins wrote:
>>>> Gordon Burditt wrote:
>>> ....
>>>>> I find the warning some compilers generate about uninitialized
>>>>> variables useful, and I really don't want to defeat it by getting
>>>>> into the habit of always initializing variables using some value I
>>>>> don't think about much (especially I don't want to initialize it
>>>>> before having thought much about the code that will use it).
>>>>
>>>> Why on Earth would you introduce a variable if you don't know how it
>>>> would be used?
>>>
>>> He wasn't talking about introducing a variable, but about initializing
>>> one. He wasn't talking about not knowing how it would be used, but about
>>> not knowing yet what value it should be given.
>>
>> I was commenting on "before having thought much about the code that will
>> use it".
>
> I hadn't noticed before - that IS odd wording. It seems to conflate the
> development sequence with sequence of statements in the code. By the
> time you've finished writing the code, any lack of knowledge you had
> when you first introduced a variable into your code should be irrelevant
> to whether or not it's initialized at the point of definition.
>
> However, not "having thought much" about a variable is not the same as
> "not knowing how it would be used". In general, the very first thought I
> have about a variable is "how it would be used". How it should be
> initialized is often a much later thought.

At the point of first use.

That way you always know how it is going to be used and what the correct 
initial value is.  No uninitialised variables to worry or warn about. 
Well, OK, there are output parameter values which don't have a "correct" 
initialisation value.  These leave you with a choice of a compiler 
warning or a dummy initial value.

-- 
Ian Collins

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


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 Fred K <fred.l.kleinschmidt@gmail.com> - 2013-09-18 14:52 -0700
  Re: why do some writers declare and define variables separately Eric Sosman <esosman@comcast-dot-net.invalid> - 2013-09-18 18:08 -0400
  Re: why do some writers declare and define variables separately T0xicCode <T0xic@co.de> - 2013-09-18 18:10 -0400
    Re: why do some writers declare and define variables separately Ken Brody <kenbrody@spamcop.net> - 2013-09-19 11:16 -0400
      Re: why do some writers declare and define variables separately T0xicCode <T0xic@co.de> - 2013-09-19 11:45 -0400
  Re: why do some writers declare and define variables separately Keith Thompson <kst-u@mib.org> - 2013-09-18 15:45 -0700
  Re: why do some writers declare and define variables separately Jens Schmidt <Jens.Schmidt-HH@gmx.de> - 2013-09-19 01:19 +0200
  Re: why do some writers declare and define variables separately Francis Glassborow <francis.glassborow@btinternet.com> - 2013-09-19 02:13 +0100
    Re: why do some writers declare and define variables separately Ben Bacarisse <ben.usenet@bsb.me.uk> - 2013-09-19 03:59 +0100
      Re: why do some writers declare and define variables separately Phil Carmody <thefatphil_demunged@yahoo.co.uk> - 2013-09-27 00:49 +0300
      Re: why do some writers declare and define variables separately Anand Hariharan <mailto.anand.hariharan@gmail.com> - 2013-10-03 15:41 -0700
        Re: why do some writers declare and define variables separately Ben Bacarisse <ben.usenet@bsb.me.uk> - 2013-10-04 00:42 +0100
    Re: why do some writers declare and define variables separately Eric Sosman <esosman@comcast-dot-net.invalid> - 2013-09-19 00:01 -0400
      Re: why do some writers declare and define variables separately David Brown <david@westcontrol.removethisbit.com> - 2013-09-19 10:17 +0200
      Re: why do some writers declare and define variables separately "osmium" <r124c4u102@comcast.net> - 2013-09-19 06:44 -0500
      Re: why do some writers declare and define variables separately Les Cargill <lcargill99@comcast.com> - 2013-09-19 08:00 -0500
        Re: why do some writers declare and define variables separately Noob <root@127.0.0.1> - 2013-09-19 15:12 +0200
        Re: why do some writers declare and define variables separately Keith Thompson <kst-u@mib.org> - 2013-09-19 08:31 -0700
          Re: why do some writers declare and define variables separately Eric Sosman <esosman@comcast-dot-net.invalid> - 2013-09-19 11:35 -0400
            Re: why do some writers declare and define variables separately Keith Thompson <kst-u@mib.org> - 2013-09-19 12:16 -0700
              Re: why do some writers declare and define variables separately Eric Sosman <esosman@comcast-dot-net.invalid> - 2013-09-19 15:32 -0400
                Re: why do some writers declare and define variables separately Tim Rentsch <txr@alumni.caltech.edu> - 2013-09-22 12:36 -0700
        Re: why do some writers declare and define variables separately Tim Rentsch <txr@alumni.caltech.edu> - 2013-09-22 11:28 -0700
          Re: why do some writers declare and define variables separately Öö Tiib <ootiib@hot.ee> - 2013-09-23 03:26 -0700
            Re: why do some writers declare and define variables separately Tim Rentsch <txr@alumni.caltech.edu> - 2013-09-24 20:33 -0700
              Re: why do some writers declare and define variables separately Öö Tiib <ootiib@hot.ee> - 2013-09-25 04:37 -0700
              Re: why do some writers declare and define variables separately Keith Thompson <kst-u@mib.org> - 2013-09-25 08:24 -0700
                Re: why do some writers declare and define variables separately glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2013-09-25 19:08 +0000
          Re: why do some writers declare and define variables separately Les Cargill <lcargill99@comcast.com> - 2013-09-25 17:37 -0500
    Re: why do some writers declare and define variables separately Tim Rentsch <txr@alumni.caltech.edu> - 2013-09-22 11:34 -0700
  Re: why do some writers declare and define variables separately gordonb.t5wsh@burditt.org (Gordon Burditt) - 2013-09-25 05:29 -0500
    Re: why do some writers declare and define variables separately Ian Collins <ian-news@hotmail.com> - 2013-09-25 22:35 +1200
      Re: why do some writers declare and define variables separately David Brown <david@westcontrol.removethisbit.com> - 2013-09-25 13:02 +0200
      Re: why do some writers declare and define variables separately James Kuyper <jameskuyper@verizon.net> - 2013-09-25 08:39 -0400
        Re: why do some writers declare and define variables separately Keith Thompson <kst-u@mib.org> - 2013-09-25 08:23 -0700
        Re: why do some writers declare and define variables separately Ian Collins <ian-news@hotmail.com> - 2013-09-26 08:06 +1200
          Re: why do some writers declare and define variables separately James Kuyper <jameskuyper@verizon.net> - 2013-09-25 16:38 -0400
            Re: why do some writers declare and define variables separately Ian Collins <ian-news@hotmail.com> - 2013-09-26 09:17 +1200
              Re: why do some writers declare and define variables separately Öö Tiib <ootiib@hot.ee> - 2013-09-25 14:32 -0700
                Re: why do some writers declare and define variables separately Ian Collins <ian-news@hotmail.com> - 2013-09-26 09:50 +1200
              Re: why do some writers declare and define variables separately Ian Collins <ian-news@hotmail.com> - 2013-09-26 09:55 +1200
              Re: why do some writers declare and define variables separately James Kuyper <jameskuyper@verizon.net> - 2013-09-25 18:50 -0400
                Re: why do some writers declare and define variables separately Ian Collins <ian-news@hotmail.com> - 2013-09-26 11:17 +1200
                Re: why do some writers declare and define variables separately James Kuyper <jameskuyper@verizon.net> - 2013-09-25 21:26 -0400
                Re: why do some writers declare and define variables separately Ian Collins <ian-news@hotmail.com> - 2013-09-26 13:50 +1200
      Re: why do some writers declare and define variables separately Noob <root@127.0.0.1> - 2013-09-25 15:55 +0200
        Re: why do some writers declare and define variables separately James Kuyper <jameskuyper@verizon.net> - 2013-09-25 10:03 -0400
          Re: why do some writers declare and define variables separately Phil Carmody <thefatphil_demunged@yahoo.co.uk> - 2013-09-27 01:29 +0300
      Re: why do some writers declare and define variables separately Phil Carmody <thefatphil_demunged@yahoo.co.uk> - 2013-09-27 01:20 +0300
    Re: why do some writers declare and define variables separately David Brown <david@westcontrol.removethisbit.com> - 2013-09-25 13:05 +0200
      Re: why do some writers declare and define variables separately Ben Bacarisse <ben.usenet@bsb.me.uk> - 2013-09-25 23:01 +0100
        Re: why do some writers declare and define variables separately James Kuyper <jameskuyper@verizon.net> - 2013-09-25 18:56 -0400
          Re: why do some writers declare and define variables separately David Brown <david@westcontrol.removethisbit.com> - 2013-09-26 09:10 +0200
            Re: why do some writers declare and define variables separately James Kuyper <jameskuyper@verizon.net> - 2013-09-26 07:31 -0400
              Re: why do some writers declare and define variables separately David Brown <david@westcontrol.removethisbit.com> - 2013-09-26 13:58 +0200
                Re: why do some writers declare and define variables separately James Kuyper <jameskuyper@verizon.net> - 2013-09-26 09:12 -0400
  Re: why do some writers declare and define variables separately Michael Lenz <unrest@nullvector.org> - 2013-10-03 19:06 +0000
    Re: why do some writers declare and define variables separately James Kuyper <jameskuyper@verizon.net> - 2013-10-03 15:26 -0400
  Re: why do some writers declare and define variables separately Dag-Erling Smørgrav <des@des.no> - 2013-10-03 21:15 +0200

csiph-web