🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: rec.games.programmer
Article #2058

Re: Should I learn C or C++ first?

#2058
From: Eric SAMBACH
Date: Tue, 12 Sep 1995 07:14
38 lines
2030 bytes
vancleef@ohstpy.mps.ohio-state.edu wrote:
: In article <8biTwcM6hDXK083yn@encomix.es>, marauder@encomix.es (Marauder) writes:
: > danker@hardy.ocs.mq.edu.au (Duncan Anker) wrote:
: >    But isn't it better to have all the vars at the top, commented, indented,
: >    and initialized so you always know where to find them?

: No. I prefer to control whether or not resources will be needed in
: a routine. When you declare everything at the top you are executing all of
: thosstack allocations. I prefer to control those stack allocations, and
: being able to place a declaration in the code when I will actually
: need it is useful for both speed and memory usage.

Hmmm, well I admit I don't know how the C/C++ compilers do it, but I would 
expect that every local variable used in a function is allocated on the
at the stack at the beginning of the function no matter what!

The reason I think this is that, on x86 machines at least, local variables
are referenced like this:

  push ebp
  mov ebp, esp

  mov eax, [ebp-4]
  mov ebx, [ebp-8]

etc.

So, if the compiler doesn't allocate space for all local variables on the 
stack at the start, it won't be able to reference variables in different
scopes!

I would expect the compiler would pre-allocate local variables at the start, 
then initialise them (if necessary) where they are defined!

Anyway, really I have no idea :), but it sounds good!

Bye,
	Alec
Technical Details
Message-ID: <433bvp$dge@seagoon.newcastle.edu.au>
Path: arc1-ca.pugleaf.net!firebird.newcastle.edu.au!c9223826
References: <40o2ee$aqp@deyke3.fc.hp.com> <DDIE24.Hqw@info.uucp> <8biTwcM6hDXK083yn@encomix.es> <1995Sep7.030214.8090@ohstpy>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!firebird.newcastle.edu.au!c9223826
From: c9223826@firebird.newcastle.edu.au (Eric SAMBACH)
Newsgroups: rec.games.programmer,comp.lang.c++
Subject: Re: Should I learn C or C++ first?
Followup-To: rec.games.programmer,comp.lang.c++
Date: 12 Sep 1995 07:14:01 GMT
Organization: The University of Newcastle
Message-ID: <433bvp$dge@seagoon.newcastle.edu.au>
References: <40o2ee$aqp@deyke3.fc.hp.com> <DDIE24.Hqw@info.uucp> <8biTwcM6hDXK083yn@encomix.es> <1995Sep7.030214.8090@ohstpy>
NNTP-Posting-Host: firebird.newcastle.edu.au
X-Newsreader: TIN [version 1.2 PL2]