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


Groups > comp.lang.c > #62931 > unrolled thread

Do variables need to be initialized?

Started byfl <rxjwg98@gmail.com>
First post2015-06-01 16:48 -0700
Last post2015-06-05 10:56 -0700
Articles 1 on this page of 41 — 15 participants

Back to article view | Back to comp.lang.c


Contents

  Do variables need to be initialized? fl <rxjwg98@gmail.com> - 2015-06-01 16:48 -0700
    Re: Do variables need to be initialized? Richard Heathfield <rjh@cpax.org.uk> - 2015-06-02 00:55 +0100
      Re: Do variables need to be initialized? Joe Pfeiffer <pfeiffer@cs.nmsu.edu> - 2015-06-01 18:22 -0600
        Re: Do variables need to be initialized? Keith Thompson <kst-u@mib.org> - 2015-06-02 08:05 -0700
          Re: Do variables need to be initialized? Tim Rentsch <txr@alumni.caltech.edu> - 2015-07-11 08:07 -0700
            Re: Do variables need to be initialized? Keith Thompson <kst-u@mib.org> - 2015-07-11 16:47 -0700
              Re: Do variables need to be initialized? Tim Rentsch <txr@alumni.caltech.edu> - 2015-07-15 07:42 -0700
        Re: Do variables need to be initialized? Tim Rentsch <txr@alumni.caltech.edu> - 2015-07-11 08:03 -0700
    Re: Do variables need to be initialized? David Brown <david.brown@hesbynett.no> - 2015-06-02 09:15 +0200
      Re: Do variables need to be initialized? Tim Rentsch <txr@alumni.caltech.edu> - 2015-07-11 08:09 -0700
    Re: Do variables need to be initialized? David Kleinecke <dkleinecke@gmail.com> - 2015-06-03 09:30 -0700
      Re: Do variables need to be initialized? gwowen <gwowen@gmail.com> - 2015-06-03 09:41 -0700
        Re: Do variables need to be initialized? David Kleinecke <dkleinecke@gmail.com> - 2015-06-04 10:17 -0700
          Re: Do variables need to be initialized? Stephen Sprunk <stephen@sprunk.org> - 2015-06-05 11:10 -0500
            Re: Do variables need to be initialized? Bartc <bc@freeuk.com> - 2015-06-05 18:22 +0100
              Re: Do variables need to be initialized? Joe Pfeiffer <pfeiffer@cs.nmsu.edu> - 2015-06-05 20:54 -0600
                Re: Do variables need to be initialized? Ian Collins <ian-news@hotmail.com> - 2015-06-06 15:49 +1200
                  Re: Do variables need to be initialized? Dr Nick <nospam-4@temporary-address.org.uk> - 2015-06-06 08:42 +0100
                    Re: Do variables need to be initialized? Keith Thompson <kst-u@mib.org> - 2015-06-06 13:11 -0700
                      Re: Do variables need to be initialized? Dr Nick <nospam-4@temporary-address.org.uk> - 2015-06-07 16:58 +0100
                  Re: Do variables need to be initialized? Bartc <bc@freeuk.com> - 2015-06-06 11:01 +0100
                    Re: Do variables need to be initialized? Ian Collins <ian-news@hotmail.com> - 2015-06-07 09:07 +1200
                  Re: Do variables need to be initialized? Joe Pfeiffer <pfeiffer@cs.nmsu.edu> - 2015-06-06 15:06 -0600
                    Re: Do variables need to be initialized? gwowen <gwowen@gmail.com> - 2015-06-08 05:39 -0700
                      Re: Do variables need to be initialized? Bartc <bc@freeuk.com> - 2015-06-08 14:10 +0100
                        Re: Do variables need to be initialized? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-06-08 14:21 +0100
                          Re: Do variables need to be initialized? Bartc <bc@freeuk.com> - 2015-06-08 14:34 +0100
                            Re: Do variables need to be initialized? David Brown <david.brown@hesbynett.no> - 2015-06-08 16:51 +0200
                              Re: Do variables need to be initialized? Richard Heathfield <rjh@cpax.org.uk> - 2015-06-08 16:15 +0100
                              Re: Do variables need to be initialized? Bartc <bc@freeuk.com> - 2015-06-08 17:31 +0100
                                Re: Do variables need to be initialized? Ian Collins <ian-news@hotmail.com> - 2015-06-09 08:06 +1200
                                  Re: Do variables need to be initialized? Bartc <bc@freeuk.com> - 2015-06-08 22:58 +0100
                            Re: Do variables need to be initialized? Keith Thompson <kst-u@mib.org> - 2015-06-08 08:27 -0700
                        Re: Do variables need to be initialized? gwowen <gwowen@gmail.com> - 2015-06-08 08:01 -0700
              Re: Do variables need to be initialized? Stephen Sprunk <stephen@sprunk.org> - 2015-06-06 11:11 -0500
                Re: Do variables need to be initialized? Bartc <bc@freeuk.com> - 2015-06-06 19:09 +0100
                  Re: Do variables need to be initialized? Robert Wessel <robertwessel2@yahoo.com> - 2015-06-06 13:57 -0500
                    Re: Do variables need to be initialized? Keith Thompson <kst-u@mib.org> - 2015-06-06 13:52 -0700
                      Re: Do variables need to be initialized? James Kuyper <jameskuyper@verizon.net> - 2015-06-06 20:57 -0400
                  Re: Do variables need to be initialized? Stephen Sprunk <stephen@sprunk.org> - 2015-06-10 14:33 -0500
            Re: Do variables need to be initialized? Keith Thompson <kst-u@mib.org> - 2015-06-05 10:56 -0700

Page 3 of 3 — ← Prev page 1 2 [3]


#62998

FromKeith Thompson <kst-u@mib.org>
Date2015-06-05 10:56 -0700
Message-ID<878ubyt4wv.fsf@kst-u.example.com>
In reply to#62996
Stephen Sprunk <stephen@sprunk.org> writes:
> On 04-Jun-15 12:17, David Kleinecke wrote:
>> On Wednesday, June 3, 2015 at 9:42:03 AM UTC-7, gwowen wrote:
>>> David Kleinecke wrote:
>>>> It's all a matter of style.
>>> 
>>> True, but ... in post C90 versions, where you can mix code and
>>> declarations, its often a good question to ask "if I don't know
>>> what the initial value is, why am I declaring it here?"
>>> ...
>>
>> Same points still apply. The C90 (and earlier) rule against mixing 
>> declarations and statements was clearly wrong and I cannot imagine 
>> why they imposed it. One reason it was silly is that mixing changes 
>> nothing significant.
>
> AIUI, early compilers worked line-by-line, and they needed all the
> declarations in one place so they could set up the stack frame before
> translating the following statements into code.  If a declaration came
> later, then there would be no space left in the stack frame to put the
> variable, and they couldn't go back and increase the frame size because
> they'd already output the frame setup code--and the code in between that
> assumed a particular frame size.
>
> Once you can assume optimizing compilers that look at entire functions
> (or at least blocks) before outputting anything, mixing declarations and
> statements is an obvious improvement.

Even relatively primitive one-pass compilers can, and in some cases
must, do backpatching.

A compiler could generate code (machine, assembly, or intermediate)
on entry to a function to allocate a stack frame of some minimal
size, and remember where that code is.  On encountering each local
declaration, it could update that code with the new stack frame size.

Requiring declarations and statements to be separated within a
block probably does make a compiler's job a bit easier, but not by
a whole lot.

In any case, even C90 allows declarations in nested blocks, and most
compilers (I think) allocate the stack frame for an entire function on
entry rather than allocation memory for each block as it's entered.
Handling that is probably about as difficult as handling mixed
declarations and statements within a block.

-- 
Keith Thompson (The_Other_Keith) kst-u@mib.org  <http://www.ghoti.net/~kst>
Working, but not speaking, for JetHead Development, Inc.
"We must do something.  This is something.  Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"

[toc] | [prev] | [standalone]


Page 3 of 3 — ← Prev page 1 2 [3]

Back to top | Article view | comp.lang.c


csiph-web