Groups | Search | Server Info | Login | Register


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

Re: why do some writers declare and define variables separately

From James Kuyper <jameskuyper@verizon.net>
Newsgroups comp.lang.c.moderated
Subject Re: why do some writers declare and define variables separately
Date 2013-10-08 16:38 -0500
Organization A noiseless patient Spider
Message-ID <clcm-20131008-0006@plethora.net> (permalink)
References <clcm-20130918-0002@plethora.net> <clcm-20131003-0002@plethora.net>

Show all headers | View raw


On 10/03/2013 02:37 PM, mt wrote:
...
> I don't really know, and I am sure there is a good explanation for it. But from my own coding experience, I prefer to initialize variables when I declare them because if you don't, it may be some random number and you could use it and not get an error that its being used. 

I prefer to leave variables uninitialized if I cannot initialize them
with the value they're supposed to have the next time their value is
read. That's because any decent compiler will give you a warning if its
analysis of the code flow suggests that there's a possibility of the
value of that variable being read before it gets written. Initializing a
 variable with a value that's not actually intended to be used turns off
that warning, because the compiler doesn't know that you don't intend it
to be used.
-- 
James Kuyper
-- 
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 | 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 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