Path: csiph.com!weretis.net!feeder6.news.weretis.net!news.misty.com!news.iecc.com!.POSTED.news.iecc.com!nerds-end From: Kaz Kylheku <864-117-4973@kylheku.com> Newsgroups: comp.compilers Subject: Re: another C-like language? was Compilers :) Date: Sat, 14 Jan 2023 19:07:50 -0000 (UTC) Organization: A noiseless patient Spider Sender: news@iecc.com Approved: comp.compilers@iecc.com Message-ID: <23-01-057@comp.compilers> References: <23-01-001@comp.compilers> <23-01-002@comp.compilers> <23-01-003@comp.compilers> <23-01-008@comp.compilers> <23-01-016@comp.compilers> <23-01-029@comp.compilers> <23-01-052@comp.compilers> 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 X-submission-address: compilers@iecc.com X-moderator-address: compilers-request@iecc.com X-FAQ-and-archives: http://compilers.iecc.com Xref: csiph.com comp.compilers:3325 On 2023-01-13, Luke A. Guest wrote: > On 09/01/2023 17:41, Kaz Kylheku wrote: >> On 2023-01-06, David Brown 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]