Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 29 Jan 2005 14:56:54 +0100
From:      "Poul-Henning Kamp" <phk@phk.freebsd.dk>
To:        des@des.no (=?iso-8859-1?q?Dag-Erling_Sm=F8rgrav?=)
Cc:        Paul Richards <paul@originative.co.uk>
Subject:   Re: c99/c++ localised variable definition 
Message-ID:  <45705.1107007014@critter.freebsd.dk>
In-Reply-To: Your message of "Sat, 29 Jan 2005 14:11:02 %2B0100." <xzpr7k4gz2x.fsf@dwp.des.no> 

next in thread | previous in thread | raw e-mail | index | archive | help
In message <xzpr7k4gz2x.fsf@dwp.des.no>, =?iso-8859-1?q?Dag-Erling_Sm=F8rgrav?= writes:
>Paul Richards <paul@originative.co.uk> writes:
>> People used to programming in C++ or Perl (and many others) are used
>> to defining variables as near to use as possible. This have never been
>> possible before in C, but now with c99 it is.
>
>It's a very bad idea, because you can introduce new variables whenever
>you feel like, but you can't destroy them.  Defining variables at the
>top of the scope forces you to think about which variables you need
>and how long they will live.  Defining them on an ad hoc basis leads
>to sloppy programming and stack abuse.

Well... In ideal theory the compiler should reuse the stackspace
but in practice we can't rely on it happening.

I personally do like to be able to judge how much gunk a function
puts on the stack by looking at the top of the function, rather
than to have to hunt into umpteen levels for a "char buf[FAR_TOO_MUCH]".

Far too many of the cases which define local scope variables in our
current code base is bacause of lazy programmers who couldn't be
bothered to locate an unused variable amongst the ones we already
have and a minority is where the inner scope should really have
been pulled into a separate function.

-- 
Poul-Henning Kamp       | UNIX since Zilog Zeus 3.20
phk@FreeBSD.ORG         | TCP/IP since RFC 956
FreeBSD committer       | BSD since 4.3-tahoe    
Never attribute to malice what can adequately be explained by incompetence.



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?45705.1107007014>