Re: another C-like language? was Compilers :)

Kaz Kylheku <864-117-4973@kylheku.com>
Sat, 14 Jan 2023 19:07:50 -0000 (UTC)

          From comp.compilers

Related articles
[16 earlier articles]
Re: another C-like language? was Compilers :) tkoenig@netcologne.de (Thomas Koenig) (2023-01-11)
Re: another C-like language? was Compilers :) 864-117-4973@kylheku.com (Kaz Kylheku) (2023-01-11)
Re: another C-like language? was Compilers :) findlaybill@blueyonder.co.uk (Bill Findlay) (2023-01-11)
Re: another C-like language? was Compilers :) david.brown@hesbynett.no (David Brown) (2023-01-11)
Re: another C-like language? was Compilers :) laguest@archeia.com (Luke A. Guest) (2023-01-13)
Re: another C-like language? was Compilers :) gneuner2@comcast.net (George Neuner) (2023-01-13)
Re: another C-like language? was Compilers :) 864-117-4973@kylheku.com (Kaz Kylheku) (2023-01-14)
Re: another C-like language? was Compilers :) marblypup@yahoo.co.uk (marb...@yahoo.co.uk) (2023-01-15)
Re: another C-like language? was Compilers :) marblypup@yahoo.co.uk (marb...@yahoo.co.uk) (2023-01-15)
Re: another C-like language? was Compilers :) anw@cuboid.co.uk (Andy Walker) (2023-01-15)
| List of all articles for this month |
From: Kaz Kylheku <864-117-4973@kylheku.com>
Newsgroups: comp.compilers
Date: Sat, 14 Jan 2023 19:07:50 -0000 (UTC)
Organization: A noiseless patient Spider
References: 23-01-001 23-01-002 23-01-003 23-01-008 23-01-016 23-01-029 23-01-052
Injection-Info: gal.iecc.com; posting-host="news.iecc.com:2001:470:1f07:1126:0:676f:7373:6970"; logging-data="64570"; mail-complaints-to="abuse@iecc.com"
Keywords: C, history, comment
Posted-Date: 14 Jan 2023 15:14:27 EST

On 2023-01-13, Luke A. Guest <laguest@archeia.com> wrote:
> On 09/01/2023 17:41, Kaz Kylheku wrote:
>> On 2023-01-06, David Brown <david.brown@hesbynett.no> wrote:
>>> don't want to go through them all, but I agree with you that the style
>>> of "all your declarations at the start of the function" is long
>>> outdated, and often - but not universally - considered a bad idea.)
>>
>> Declarations have never been required to be at the top of a function in
>> C, because they can be in any compound statement block. I think
>> that goes all the way back to the B language. [Nope, see the next message. -John]
>
> When I learnt C, you had to define your variables at the top of the
> block {} whether that's a function or a block within the function somewhere.


Well yes; that is the situation in ISO C 90. ISO C 99 introduced mixed
declarations and statements. Or, perhaps we should say, the C++ dialect
introduced this (and standardized it first, in 1998).


>> The "Variables at the top" meme may be something coming from Pascal.
>
> Nope. Algol. C is an Algol derived language.
>
>> IIRC, in Pascal, compound statements aren't full blocks; they cannot
>> have VAR declarations.
>>
>> When programmers abandoned Pascal in the 1980s, they carried over this
>> habit into C.
>
> Nope, this was defined in the C spec and the K&R book. Apparently this
> has been relaxed recently-ish and now variables can be defined anywhere.


The discussion is about whether variables must be declared at the top of
the entire function, even if it has nested compound statements where
some of them could be declared.


The top-of-function restriction exists in Pascal; compound statements
do not have VAR section.


--
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
Mastodon: @Kazinator@mstdn.ca
[Algol60 allowed declarations at the start of every block, so I think
it was one of the things Pascal left out to make it easier to compile.
It does make one-pass compiling with tiny memory easier. These days,
that's irrelevant. -John]


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.