Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

All life evolves by the differential survival of replicating entities. -- Dawkins


devel / comp.compilers / Re: another C-like language? was Compilers :)

SubjectAuthor
* Re: another C-like language? was Compilers :)Steve Limb
+* Re: another C-like language? was Compilers :)gah4
|`* Re: another C-like language? was Compilers :)Aharon Robbins
| `- Re: another C-like language? was Compilers :)gah4
`* Re: another C-like language? was Compilers :)marb...@yahoo.co.uk
 +- Re: another C-like language? was Compilers :)gah4
 +* Re: another C-like language? was Compilers :)David Brown
 |`* Re: another C-like language? was Compilers :)Kaz Kylheku
 | +* Re: another C-like language? was Compilers :)David Brown
 | |+* Re: another C-like language? was Compilers :)gah4
 | ||`* Re: another C-like language? was Compilers :)David Brown
 | || +- Re: back in the 60s, another C-like language? was Compilers :)gah4
 | || `- Re: another C-like language? was Compilers :)marb...@yahoo.co.uk
 | |+* Re: another C-like language? was Compilers :)Kaz Kylheku
 | ||`- Re: Scheme is not another C-like language? was Compilers :)George Neuner
 | |`- Re: another C-like language? was Compilers :)Bill Findlay
 | +* Re: another C-like language? was Compilers :)Thomas Koenig
 | |`* Re: another C-like language? was Compilers :)marb...@yahoo.co.uk
 | | `- Re: another C-like language? was Compilers :)Andy Walker
 | `* Re: another C-like language? was Compilers :)Luke A. Guest
 |  +- Re: another C-like language? was Compilers :)George Neuner
 |  `- Re: another C-like language? was Compilers :)Kaz Kylheku
 `* Re: another C-like language? was Compilers :)marb...@yahoo.co.uk
  `* Re: another C-like language? was Compilers :)David Brown
   +* Re: another C-like language? was Compilers :)Hans-Peter Diettrich
   |`- Re: C scopes, another C-like language? was Compilers :)David Brown
   `- Re: another C-like language? was Compilers :)Keith Thompson

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

<23-01-003@comp.compilers>

 copy mid

https://www.novabbs.com/devel/article-flat.php?id=631&group=comp.compilers#631

 copy link   Newsgroups: comp.compilers
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!news.iecc.com!.POSTED.news.iecc.com!nerds-end
From: stephenj...@gmail.com (Steve Limb)
Newsgroups: comp.compilers
Subject: Re: another C-like language? was Compilers :)
Date: Tue, 3 Jan 2023 16:24:05 +0000
Organization: Compilers Central
Sender: news@iecc.com
Approved: comp.compilers@iecc.com
Message-ID: <23-01-003@comp.compilers>
References: <23-01-001@comp.compilers> <23-01-002@comp.compilers>
MIME-Version: 1.0 (Mac OS X Mail 16.0 \(3731.300.101.1.3\))
Content-Type: text/plain; charset="us-ascii"
Injection-Info: gal.iecc.com; posting-host="news.iecc.com:2001:470:1f07:1126:0:676f:7373:6970";
logging-data="14769"; mail-complaints-to="abuse@iecc.com"
Keywords: design, C
Posted-Date: 03 Jan 2023 12:45:14 EST
X-submission-address: compilers@iecc.com
X-moderator-address: compilers-request@iecc.com
X-FAQ-and-archives: http://compilers.iecc.com
In-Reply-To: <23-01-002@comp.compilers>
 by: Steve Limb - Tue, 3 Jan 2023 16:24 UTC

I’m not sure there would be that much demand for a cut down C.

I too am working on a language - https://www.ek9.io/ . I’m not sure that
will get any traction either!

But it is technically challenging and interesting grappling with the
compromises and technologies involved.

My main drive has been to experiment with syntax in different forms and see
how they feel and also
roll in loads (probably an excessive amount) of much higher level concepts.

> On 2 Jan 2023, at 20:52, Spiros Bousbouras <spibou@gmail.com> wrote:
>
> On Mon, 2 Jan 2023 12:28:12 +0200
> "Tristan B. Velloza Kildaire" <deavmi@redxen.eu> wrote:
>> I am currently working on my own compiler for something like C but with
>> minimal object orientation support and no features like
>> templating/generics etc etc.
>>
>> Trying to get a feeler out there for anyone who would be interested in
>> using such a language, obviously the project is something I work on in
>> my spare time but I have written everything from scratch.
>
> Knowing what you are trying to achieve i.e. why you are creating a new
> programming language would be useful. On which operating systems is it
> going to work ? What will be the license ?
>
>> I plan to, by
>> the end of 2023 hopefully, have a full release out. The code emit is
>> already working well and so is the dependency tree algorithmn.
>
> Code emitter for what targets ?

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

<23-01-004@comp.compilers>

 copy mid

https://www.novabbs.com/devel/article-flat.php?id=632&group=comp.compilers#632

 copy link   Newsgroups: comp.compilers
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!news.iecc.com!.POSTED.news.iecc.com!nerds-end
From: gah...@u.washington.edu (gah4)
Newsgroups: comp.compilers
Subject: Re: another C-like language? was Compilers :)
Date: Tue, 3 Jan 2023 12:52:06 -0800 (PST)
Organization: Compilers Central
Sender: news@iecc.com
Approved: comp.compilers@iecc.com
Message-ID: <23-01-004@comp.compilers>
References: <23-01-001@comp.compilers> <23-01-002@comp.compilers> <23-01-003@comp.compilers>
MIME-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: 8bit
Injection-Info: gal.iecc.com; posting-host="news.iecc.com:2001:470:1f07:1126:0:676f:7373:6970";
logging-data="48074"; mail-complaints-to="abuse@iecc.com"
Keywords: C, design
Posted-Date: 03 Jan 2023 18:15:08 EST
X-submission-address: compilers@iecc.com
X-moderator-address: compilers-request@iecc.com
X-FAQ-and-archives: http://compilers.iecc.com
In-Reply-To: <23-01-003@comp.compilers>
 by: gah4 - Tue, 3 Jan 2023 20:52 UTC

On Tuesday, January 3, 2023 at 9:45:17 AM UTC-8, Steve Limb wrote:
> I’m not sure there would be that much demand for a cut down C.

I was reading it as a cut down C++, or maybe a cut-up C.

If you think that C++ has too many features, then I can see a reduced
version. Personally, I think that is why I like Java over C++.

Well, for one, it is more C-like than C++.

Otherwise, I believe the source for the original C++ compiler, which
converted to C for a C compiler, is still around, and could be used as
a start for a new C++ like language.

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

<23-01-005@comp.compilers>

 copy mid

https://www.novabbs.com/devel/article-flat.php?id=633&group=comp.compilers#633

 copy link   Newsgroups: comp.compilers
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!news.iecc.com!.POSTED.news.iecc.com!nerds-end
From: arn...@skeeve.com (Aharon Robbins)
Newsgroups: comp.compilers
Subject: Re: another C-like language? was Compilers :)
Date: Wed, 4 Jan 2023 17:12:17 -0000 (UTC)
Organization: Aioe.org NNTP Server
Sender: news@iecc.com
Approved: comp.compilers@iecc.com
Message-ID: <23-01-005@comp.compilers>
References: <23-01-001@comp.compilers> <23-01-002@comp.compilers> <23-01-003@comp.compilers> <23-01-004@comp.compilers>
Injection-Info: gal.iecc.com; posting-host="news.iecc.com:2001:470:1f07:1126:0:676f:7373:6970";
logging-data="79652"; mail-complaints-to="abuse@iecc.com"
Keywords: C, design, history, comment
Posted-Date: 04 Jan 2023 13:26:55 EST
X-submission-address: compilers@iecc.com
X-moderator-address: compilers-request@iecc.com
X-FAQ-and-archives: http://compilers.iecc.com
 by: Aharon Robbins - Wed, 4 Jan 2023 17:12 UTC

In article <23-01-004@comp.compilers>, gah4 <gah4@u.washington.edu> wrote:
>Otherwise, I believe the source for the original C++ compiler, which
>converted to C for a C compiler, is still around, and could be used as
>a start for a new C++ like language.

This is true that it's around, but I think it has copyright / license
limitations that would prevent building something new on top of it.

Arnold
--
Aharon (Arnold) Robbins arnold AT skeeve DOT com

[The copy at the computer history museum says "The source code in this
section is posted with the permission of the copyright owner for
historical research purposes only." It's from 1997 so I would think
it's a long way from modern C++. -John]

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

<23-01-006@comp.compilers>

 copy mid

https://www.novabbs.com/devel/article-flat.php?id=634&group=comp.compilers#634

 copy link   Newsgroups: comp.compilers
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!news.iecc.com!.POSTED.news.iecc.com!nerds-end
From: gah...@u.washington.edu (gah4)
Newsgroups: comp.compilers
Subject: Re: another C-like language? was Compilers :)
Date: Wed, 4 Jan 2023 12:39:10 -0800 (PST)
Organization: Compilers Central
Sender: news@iecc.com
Approved: comp.compilers@iecc.com
Message-ID: <23-01-006@comp.compilers>
References: <23-01-001@comp.compilers> <23-01-002@comp.compilers> <23-01-003@comp.compilers> <23-01-004@comp.compilers> <23-01-005@comp.compilers>
MIME-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
Injection-Info: gal.iecc.com; posting-host="news.iecc.com:2001:470:1f07:1126:0:676f:7373:6970";
logging-data="10575"; mail-complaints-to="abuse@iecc.com"
Keywords: C, design, comment
Posted-Date: 04 Jan 2023 16:12:48 EST
X-submission-address: compilers@iecc.com
X-moderator-address: compilers-request@iecc.com
X-FAQ-and-archives: http://compilers.iecc.com
In-Reply-To: <23-01-005@comp.compilers>
 by: gah4 - Wed, 4 Jan 2023 20:39 UTC

On Wednesday, January 4, 2023 at 10:26:58 AM UTC-8, Aharon Robbins wrote:

(snip, where I wrote about the original C++ compiler.)

> This is true that it's around, but I think it has copyright / license
> limitations that would prevent building something new on top of it.

> [The copy at the computer history museum says "The source code in this
> section is posted with the permission of the copyright owner for
> historical research purposes only." It's from 1997 so I would think
> it's a long way from modern C++. -John]

It sounds like the OP is, so far, in a research project.

But also seems to want something like C++, but without all the
fancy new features. Starting with a compiler without those features,
seemed like a good way to go.

(I believe some have suggested, over the years, a C--, though
exactly which features are removed, I don't know.)

The process for starting with copyright code, and modifying it
until all copyright parts are gone, seems to be well known, though
I suspect never easy.
[I wouldn't try mutating out the copyrighted stuff. Depending on how
aggressive the copyright holder is, they can claim copyright in the
structure and sequence of the code. And if it's a research project,
it's not that hard to make a parser and symbol table using compiler
tools better than 1997 era yacc. -John]

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

<23-01-008@comp.compilers>

 copy mid

https://www.novabbs.com/devel/article-flat.php?id=636&group=comp.compilers#636

 copy link   Newsgroups: comp.compilers
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!news.iecc.com!.POSTED.news.iecc.com!nerds-end
From: marbly...@yahoo.co.uk (marb...@yahoo.co.uk)
Newsgroups: comp.compilers
Subject: Re: another C-like language? was Compilers :)
Date: Thu, 5 Jan 2023 06:27:06 -0800 (PST)
Organization: Compilers Central
Sender: news@iecc.com
Approved: comp.compilers@iecc.com
Message-ID: <23-01-008@comp.compilers>
References: <23-01-001@comp.compilers> <23-01-002@comp.compilers> <23-01-003@comp.compilers>
MIME-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: 8bit
Injection-Info: gal.iecc.com; posting-host="news.iecc.com:2001:470:1f07:1126:0:676f:7373:6970";
logging-data="22109"; mail-complaints-to="abuse@iecc.com"
Keywords: C, design, comment
Posted-Date: 05 Jan 2023 09:34:32 EST
X-submission-address: compilers@iecc.com
X-moderator-address: compilers-request@iecc.com
X-FAQ-and-archives: http://compilers.iecc.com
In-Reply-To: <23-01-003@comp.compilers>
 by: marb...@yahoo.co.uk - Thu, 5 Jan 2023 14:27 UTC

On Tuesday, 3 January 2023 at 17:45:17 UTC, Steve Limb wrote:
> I’m not sure there would be that much demand for a cut down C.

I recently read (well, skimmed)
http://www.mjbauer.biz/C-less%20Reference%20Manual.pdf
"A concise subset of the C programming language".
Though I'm a bit baffled by some of Bauer's choices. Why is
`char *foo="foo", *bar="bar"; puts(foo); puts(bar);`
allowed but not
`char *foo="foo"; puts(foo); char *bar="bar"; puts(bar);`
? Admittedly, the latter is only allowed in relatively recent C, but from my
(very limited) experience writing compilers, the latter is no harder to
compile.
I idly thought about adding stuff to C-less and calling it C-more-or-less,
Cmol, for short.

I'm up for reading the source of any relatively simple compiler for, and
written in, anything C-like. I've tried making sense of the GNU C compiler a
few times. My brain may recover one day!
[If you're doing a one-pass compiler, it's easier if all the declarations are at the
beginning so you can generate the code to set up the stack frame and do initializations.
I agree that on modern computers it's not a big deal, but remember that early C compilers
ran in 24K bytes and I don't mean meagabytes. -John]

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

<23-01-013@comp.compilers>

 copy mid

https://www.novabbs.com/devel/article-flat.php?id=641&group=comp.compilers#641

 copy link   Newsgroups: comp.compilers
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!news.iecc.com!.POSTED.news.iecc.com!nerds-end
From: gah...@u.washington.edu (gah4)
Newsgroups: comp.compilers
Subject: Re: another C-like language? was Compilers :)
Date: Thu, 5 Jan 2023 16:26:47 -0800 (PST)
Organization: Compilers Central
Sender: news@iecc.com
Approved: comp.compilers@iecc.com
Message-ID: <23-01-013@comp.compilers>
References: <23-01-001@comp.compilers> <23-01-002@comp.compilers> <23-01-003@comp.compilers> <23-01-008@comp.compilers>
MIME-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
Injection-Info: gal.iecc.com; posting-host="news.iecc.com:2001:470:1f07:1126:0:676f:7373:6970";
logging-data="36844"; mail-complaints-to="abuse@iecc.com"
Keywords: C, tools
Posted-Date: 05 Jan 2023 19:29:40 EST
X-submission-address: compilers@iecc.com
X-moderator-address: compilers-request@iecc.com
X-FAQ-and-archives: http://compilers.iecc.com
In-Reply-To: <23-01-008@comp.compilers>
 by: gah4 - Fri, 6 Jan 2023 00:26 UTC

On Thursday, January 5, 2023 at 6:34:35 AM UTC-8, marb...@yahoo.co.uk wrote:

(snip)
> I'm up for reading the source of any relatively simple compiler for, and
> written in, anything C-like. I've tried making sense of the GNU C compiler a
> few times. My brain may recover one day!

Some years ago, I bought the LCC book.

The book explains it in some detail, in addition to any comments
in the code. As well as I know, it is meant for understanding.

It is especially convenient if you only what to retarget the code
generator, for a new (or existing) machine.

I have no desire to look at gcc.

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

<23-01-016@comp.compilers>

 copy mid

https://www.novabbs.com/devel/article-flat.php?id=644&group=comp.compilers#644

 copy link   Newsgroups: comp.compilers
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!news.iecc.com!.POSTED.news.iecc.com!nerds-end
From: david.br...@hesbynett.no (David Brown)
Newsgroups: comp.compilers
Subject: Re: another C-like language? was Compilers :)
Date: Fri, 6 Jan 2023 15:39:05 +0100
Organization: A noiseless patient Spider
Sender: news@iecc.com
Approved: comp.compilers@iecc.com
Message-ID: <23-01-016@comp.compilers>
References: <23-01-001@comp.compilers> <23-01-002@comp.compilers> <23-01-003@comp.compilers> <23-01-008@comp.compilers>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Info: gal.iecc.com; posting-host="news.iecc.com:2001:470:1f07:1126:0:676f:7373:6970";
logging-data="30341"; mail-complaints-to="abuse@iecc.com"
Keywords: C, design
Posted-Date: 06 Jan 2023 12:01:30 EST
X-submission-address: compilers@iecc.com
X-moderator-address: compilers-request@iecc.com
X-FAQ-and-archives: http://compilers.iecc.com
In-Reply-To: <23-01-008@comp.compilers>
Content-Language: en-GB
 by: David Brown - Fri, 6 Jan 2023 14:39 UTC

On 05/01/2023 15:27, marb...@yahoo.co.uk wrote:
> On Tuesday, 3 January 2023 at 17:45:17 UTC, Steve Limb wrote:
>> I’m not sure there would be that much demand for a cut down C.
>
> I recently read (well, skimmed)
> http://www.mjbauer.biz/C-less%20Reference%20Manual.pdf
> "A concise subset of the C programming language".
> Though I'm a bit baffled by some of Bauer's choices. Why is
> `char *foo="foo", *bar="bar"; puts(foo); puts(bar);`
> allowed but not
> `char *foo="foo"; puts(foo); char *bar="bar"; puts(bar);`
> ? Admittedly, the latter is only allowed in relatively recent C, but from my
> (very limited) experience writing compilers, the latter is no harder to
> compile.

By "relatively recent C", you mean C99 ? Mixing statements and
declarations was standardised in C nearly 25 years ago, and was probably
implemented at least a decade before that in some compilers. (Some C
compilers incorporated features from C++ that later became standardised
in C99.)

> I idly thought about adding stuff to C-less and calling it C-more-or-less,
> Cmol, for short.

There have been many "sort-of-C" languages made, as well as
"sort-of-C++". (Embedded C++ was one attempt at making a simpler subset
of C++ for use in embedded systems - despite significant backing, it has
failed completely.)

One subset of C that was useful is C--. This was aimed at being a code
generation target for higher level languages, to improve portability and
save the high level compiler writers from learning the details of
assembly language on different targets. I think these days it is more
common to target LLVM or a common virtual machine (such as JVM) for such
purposes.

The "C-less" language referenced in the link above seems to be targeting
"a first course in embedded programming". As an embedded programmer by
profession, I would not want to hire a new developer that had learned
"C-less". They would /think/ that they could program in C, but be
mislead in several areas and have learned a number of bad habits. (I
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.)

I also find it strange that this is supposedly a description of parts of
the C language, but regularly uses different terms from the C standards
and other C documentation for no visible benefit. This could only serve
to confuse the student.

> I'm up for reading the source of any relatively simple compiler for, and
> written in, anything C-like. I've tried making sense of the GNU C compiler a
> few times. My brain may recover one day!

gcc is the result of thousands of man-hours, spread over about 5 decades
and thousands of contributors. No, it is not an easy read! I think
"LCC" is probably the best choice of a simple C compiler to read and
understand - this was part of the motivation for writing it. "Tiny C
Compiler" is another option.

> [If you're doing a one-pass compiler, it's easier if all the declarations are at the
> beginning so you can generate the code to set up the stack frame and do initializations.
> I agree that on modern computers it's not a big deal, but remember that early C compilers
> ran in 24K bytes and I don't mean meagabytes. -John]

If you are writing a compiler for use by people writing code, then being
able to mix declarations and statements is hugely important - and since
generally people /use/ compilers more than they write them, the
trade-off should be on the side of the effort for the users, rather than
the compiler writers.

But if you are writing it for fun, or to learn about compiler writing,
then of course a simpler language is easier. And if your aim is for an
intermediary language generated by a higher level compiler, then a
simple subset is also convenient.

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

<23-01-020@comp.compilers>

 copy mid

https://www.novabbs.com/devel/article-flat.php?id=648&group=comp.compilers#648

 copy link   Newsgroups: comp.compilers
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!news.iecc.com!.POSTED.news.iecc.com!nerds-end
From: marbly...@yahoo.co.uk (marb...@yahoo.co.uk)
Newsgroups: comp.compilers
Subject: Re: another C-like language? was Compilers :)
Date: Sat, 7 Jan 2023 02:14:51 -0800 (PST)
Organization: Compilers Central
Sender: news@iecc.com
Approved: comp.compilers@iecc.com
Message-ID: <23-01-020@comp.compilers>
References: <23-01-001@comp.compilers> <23-01-002@comp.compilers> <23-01-003@comp.compilers> <23-01-008@comp.compilers>
MIME-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
Injection-Info: gal.iecc.com; posting-host="news.iecc.com:2001:470:1f07:1126:0:676f:7373:6970";
logging-data="74083"; mail-complaints-to="abuse@iecc.com"
Keywords: C, code, comment
Posted-Date: 08 Jan 2023 13:55:54 EST
X-submission-address: compilers@iecc.com
X-moderator-address: compilers-request@iecc.com
X-FAQ-and-archives: http://compilers.iecc.com
In-Reply-To: <23-01-008@comp.compilers>
 by: marb...@yahoo.co.uk - Sat, 7 Jan 2023 10:14 UTC

> [If you're doing a one-pass compiler, it's easier if all the declarations are at the
> beginning so you can generate the code to set up the stack frame and do initializations.
> I agree that on modern computers it's not a big deal, but remember that early C compilers
> ran in 24K bytes and I don't mean meagabytes. -John]

Presumably such a compiler would have to create 2 stack frames for
`char *foo="foo"; puts(foo); { char *bar="bar"; puts(bar); }`
[In a mutant version of C with nested scopes, I suppose so, but when C compilers
ran in 24K bytes, it didn't. -John]

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

<23-01-024@comp.compilers>

 copy mid

https://www.novabbs.com/devel/article-flat.php?id=651&group=comp.compilers#651

 copy link   Newsgroups: comp.compilers
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!news.iecc.com!.POSTED.news.iecc.com!nerds-end
From: david.br...@hesbynett.no (David Brown)
Newsgroups: comp.compilers
Subject: Re: another C-like language? was Compilers :)
Date: Sun, 8 Jan 2023 20:21:10 +0100
Organization: A noiseless patient Spider
Sender: news@iecc.com
Approved: comp.compilers@iecc.com
Message-ID: <23-01-024@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-020@comp.compilers>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Info: gal.iecc.com; posting-host="news.iecc.com:2001:470:1f07:1126:0:676f:7373:6970";
logging-data="5173"; mail-complaints-to="abuse@iecc.com"
Keywords: C, history, comment
Posted-Date: 08 Jan 2023 17:08:44 EST
X-submission-address: compilers@iecc.com
X-moderator-address: compilers-request@iecc.com
X-FAQ-and-archives: http://compilers.iecc.com
Content-Language: en-GB
In-Reply-To: <23-01-020@comp.compilers>
 by: David Brown - Sun, 8 Jan 2023 19:21 UTC

On 07/01/2023 11:14, marb...@yahoo.co.uk wrote:
>> [If you're doing a one-pass compiler, it's easier if all the declarations are at the
>> beginning so you can generate the code to set up the stack frame and do initializations.
>> I agree that on modern computers it's not a big deal, but remember that early C compilers
>> ran in 24K bytes and I don't mean meagabytes. -John]
>
> Presumably such a compiler would have to create 2 stack frames for
> `char *foo="foo"; puts(foo); { char *bar="bar"; puts(bar); }`

No. The compiler could treat this as though you had written :

char *foo = "foo";
char *bar_nested_scope_1;

puts(foo);
{
bar_nested_scope_1 = "bar";
puts(bar);
}

In other words, it can combine all the variables declared in nested
scope and act as though they were all defined at the start of the
function. It would have to take care of naming, as nested block scopes
could have identifiers that shadow outer scope names. And it may or may
not choose to allow overlapping of variables that have independent
lifetimes.

It only gets complicated when you have variable length arrays, which
would allow the declaration of an array whose size is not known at the
start of the function. But if you are supporting VLA's, you'll already
have support for more sophisticated mixes of variables and code.

> [In a mutant version of C with nested scopes, I suppose so, but when C compilers
> ran in 24K bytes, it didn't. -John]

I don't have my copy of K&R handy, or a pre-K&R Unix C manuals, but I
expect someone will correct me if I'm wrong :-) As far as I know, the C
described in "The C Programming Language" in 1978, when 24 KB was still
a big deal, supported declarations at the start of any compound
statement block. That is, nested scopes. It's possible that pre-K&R C
compilers were more limited.
[I actually used that 24K C compiler in about 1975 and I am reasonably sure
it did not let you put declarations other than in the outer block. There's
a 1978 edition of K&R at archive.org and by then it did let you put
declarations in any block. It's a little harder than what you say because
declarations in non-overlapping blocks should overlay each other, e.g.:

foo() {
int a:
...
{
int b[100];
somefunc(b);
}
{
float c[100];
otherfunc(c);
}
}

you want b and c to use the same storage. It's not hard, but it's a little
more than promoting and renaming. -John]

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

<23-01-025@comp.compilers>

 copy mid

https://www.novabbs.com/devel/article-flat.php?id=652&group=comp.compilers#652

 copy link   Newsgroups: comp.compilers
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!news.iecc.com!.POSTED.news.iecc.com!nerds-end
From: DrDiettr...@netscape.net (Hans-Peter Diettrich)
Newsgroups: comp.compilers
Subject: Re: another C-like language? was Compilers :)
Date: Mon, 9 Jan 2023 04:48:37 +0100
Organization: Compilers Central
Sender: news@iecc.com
Approved: comp.compilers@iecc.com
Message-ID: <23-01-025@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-020@comp.compilers> <23-01-024@comp.compilers>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Info: gal.iecc.com; posting-host="news.iecc.com:2001:470:1f07:1126:0:676f:7373:6970";
logging-data="22819"; mail-complaints-to="abuse@iecc.com"
Keywords: C, optimize
Posted-Date: 09 Jan 2023 11:39:31 EST
X-submission-address: compilers@iecc.com
X-moderator-address: compilers-request@iecc.com
X-FAQ-and-archives: http://compilers.iecc.com
In-Reply-To: <23-01-024@comp.compilers>
 by: Hans-Peter Diettrich - Mon, 9 Jan 2023 03:48 UTC

On 1/8/23 8:21 PM, David Brown wrote:

> In other words, it can combine all the variables declared in nested
> scope and act as though they were all defined at the start of the
> function.

AFAIR nested scopes were introduced just to allow for space saving
memory overlays. Regardless of whether a compiler really takes that
optimization *option*.

Of course problems can arise from malware assuming memory contents as
left over from a previous block, as it's not required that the compiler
initializes all local variables on block entry.

DoDi

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

<23-01-028@comp.compilers>

 copy mid

https://www.novabbs.com/devel/article-flat.php?id=655&group=comp.compilers#655

 copy link   Newsgroups: comp.compilers
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!news.iecc.com!.POSTED.news.iecc.com!nerds-end
From: david.br...@hesbynett.no (David Brown)
Newsgroups: comp.compilers
Subject: Re: C scopes, another C-like language? was Compilers :)
Date: Mon, 9 Jan 2023 18:12:22 +0100
Organization: A noiseless patient Spider
Sender: news@iecc.com
Approved: comp.compilers@iecc.com
Message-ID: <23-01-028@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-020@comp.compilers> <23-01-024@comp.compilers> <23-01-025@comp.compilers>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Info: gal.iecc.com; posting-host="news.iecc.com:2001:470:1f07:1126:0:676f:7373:6970";
logging-data="31793"; mail-complaints-to="abuse@iecc.com"
Keywords: C, history
Posted-Date: 09 Jan 2023 21:33:48 EST
X-submission-address: compilers@iecc.com
X-moderator-address: compilers-request@iecc.com
X-FAQ-and-archives: http://compilers.iecc.com
In-Reply-To: <23-01-025@comp.compilers>
Content-Language: en-GB
 by: David Brown - Mon, 9 Jan 2023 17:12 UTC

On 09/01/2023 04:48, Hans-Peter Diettrich wrote:
> On 1/8/23 8:21 PM, David Brown wrote:
>
>> In other words, it can combine all the variables declared in nested
>> scope and act as though they were all defined at the start of the
>> function.
>
> AFAIR nested scopes were introduced just to allow for space saving
> memory overlays. Regardless of whether a compiler really takes that
> optimization *option*.

I don't know the history as to /why/ block scope variables were
introduced in C - that was all before my time. But they certainly allow
you to write better structure in your code (in my opinion, anyway - I am
aware that some people think "declare all variables at the start of the
function before any code" gives better code). IMHO, local variables
should have as small a scope as practically possible. So even if I have
to use C90 (which I dislike - C99 was a big improvement), if I have a
variable that is only needed inside a loop or a conditional, I'll
declare it there.

Compilers have always been free to use lifetime analysis to merge or
overlap variables, regardless of how and where they are declared inside
a function. There have never been any requirements from the language
forcing compilers to have separate "stack slots" for variables that are
declared at the start of a function or within the same block. Of
course, compilers of old were not as sophisticated as modern compilers,
and debuggers of old were also more limited, so it was quite common to
have fixed and dedicated stack slots for each variable declared at the
start of the function. But it was never /required/ for correct
implementation of the language.

> Of course problems can arise from malware assuming memory contents as
> left over from a previous block, as it's not required that the compiler
> initializes all local variables on block entry.
>

You are required to initialise or assign to all local variables that you
read. Failing to do so is undefined behaviour (or in some
circumstances, unspecified behaviour). And it doesn't matter whether
you initialise your local variable at the start of a block, or assign to
it later when you use it - the compiler is under no obligation to make
any initialisation at the start of the block, regardless of what you
write. It only has to make sure you get the same results in the end as
you would have had if it had followed your source code directly.

If malware can execute its code inside your functions (from code
injections, buffer overflows, etc.), then all sorts of things can go
wrong. Initialising local variables at the start of a block can reduce
the risks and consequences a bit, but it will not save you.

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

<23-01-029@comp.compilers>

 copy mid

https://www.novabbs.com/devel/article-flat.php?id=656&group=comp.compilers#656

 copy link   Newsgroups: comp.compilers
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!news.iecc.com!.POSTED.news.iecc.com!nerds-end
From: 864-117-...@kylheku.com (Kaz Kylheku)
Newsgroups: comp.compilers
Subject: Re: another C-like language? was Compilers :)
Date: Mon, 9 Jan 2023 17:41:51 -0000 (UTC)
Organization: A noiseless patient Spider
Sender: news@iecc.com
Approved: comp.compilers@iecc.com
Message-ID: <23-01-029@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>
Injection-Info: gal.iecc.com; posting-host="news.iecc.com:2001:470:1f07:1126:0:676f:7373:6970";
logging-data="32133"; mail-complaints-to="abuse@iecc.com"
Keywords: C, design
Posted-Date: 09 Jan 2023 21:34:36 EST
X-submission-address: compilers@iecc.com
X-moderator-address: compilers-request@iecc.com
X-FAQ-and-archives: http://compilers.iecc.com
 by: Kaz Kylheku - Mon, 9 Jan 2023 17:41 UTC

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]

The "Variables at the top" meme may be something coming from Pascal.
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.

I hate mixed declarations and code because it's almost sa bad as
variables-at-the-top. The scope of a declaration that is just planted
into the middle of a compound statement block extends all the way to the
end of the block. There should be a smaller enclosing block which
exactly delimits the scope of that variable. If some variable is used
over seven lines of a 300 line function, those seven lines should
ideally be enclosed in curly braces, so the variable is not known
outside of those lines. Just planting an unwrapped declaration of the
variable at the function scope level (outermost block) solves only half
the problem. The scope of the variable starts close to where the
variable is used, which is good; but it still goes to the end of the
function, way past its actual semantic scope that ends at the last use.

A block like this can be repeated with copy and paste:

{
int yes = 1;
setsockopt(fd, SO_WHATEVER, &yes);
}

This cannot: you will get redefinition errors:

int yes = 1;
setsockopt(fd, SO_WHATEVER, &yes);

you have to think about ensuring that "int yes" occurs in one place
that is before the first use, and the other places assign to it.
Or invent different names.

--
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
Mastodon: @Kazinator@mstdn.ca

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

<23-01-030@comp.compilers>

 copy mid

https://www.novabbs.com/devel/article-flat.php?id=657&group=comp.compilers#657

 copy link   Newsgroups: comp.compilers
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!news.iecc.com!.POSTED.news.iecc.com!nerds-end
From: Keith.S....@gmail.com (Keith Thompson)
Newsgroups: comp.compilers
Subject: Re: another C-like language? was Compilers :)
Date: Mon, 09 Jan 2023 11:24:07 -0800
Organization: None to speak of
Sender: news@iecc.com
Approved: comp.compilers@iecc.com
Message-ID: <23-01-030@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-020@comp.compilers> <23-01-024@comp.compilers>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: gal.iecc.com; posting-host="news.iecc.com:2001:470:1f07:1126:0:676f:7373:6970";
logging-data="32833"; mail-complaints-to="abuse@iecc.com"
Keywords: C, history
Posted-Date: 09 Jan 2023 21:37:45 EST
X-submission-address: compilers@iecc.com
X-moderator-address: compilers-request@iecc.com
X-FAQ-and-archives: http://compilers.iecc.com
 by: Keith Thompson - Mon, 9 Jan 2023 19:24 UTC

David Brown <david.brown@hesbynett.no> writes:
[...]
>> [In a mutant version of C with nested scopes, I suppose so, but when C compilers
>> ran in 24K bytes, it didn't. -John]
>
> I don't have my copy of K&R handy, or a pre-K&R Unix C manuals, but I
> expect someone will correct me if I'm wrong :-) As far as I know, the C
> described in "The C Programming Language" in 1978, when 24 KB was still
> a big deal, supported declarations at the start of any compound
> statement block. That is, nested scopes. It's possible that pre-K&R C
> compilers were more limited.
> [I actually used that 24K C compiler in about 1975 and I am reasonably sure
> it did not let you put declarations other than in the outer block. There's
> a 1978 edition of K&R at archive.org and by then it did let you put
> declarations in any block. It's a little harder than what you say because
> declarations in non-overlapping blocks should overlay each other, e.g.:
>
> foo() {
> int a:
> ...
> {
> int b[100];
> somefunc(b);
> }
> {
> float c[100];
> otherfunc(c);
> }
> }
>
> you want b and c to use the same storage. It's not hard, but it's a little
> more than promoting and renaming. -John]

The 1975 C reference manual <https://www.bell-labs.com/usr/dmr/www/cman.pdf>
allows declarations at the top of a function body but not at the top of
a compound statement. K&R1 (1978) does allow declarations at the top of
a compound statement.

In the example above, you'd certainly *want* b and c to use the same
storage, but the language doesn't require it. But it's a simple enough
optimization that I'd expect all compilers to do it (or something more
sophisticated). Also, a compiler could either generate code that
allocates storage for each block on entry to the block, or that
allocates the maximum size on entry to the function. I haven't bothered
to look into what compilers actually do. (And it gets more complicated
if you introduce variable-length arrays.)

--
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
Working, but not speaking, for XCOM Labs
void Void(void) { Void(); } /* The recursive call of the void */
[On a PDP-11 or Vax, adjusting the size of local storage was a single
instruction to adjust the stack pointer at the entry to or exit from
each block. In the example above, imagine that between the two blocks
is a call to bloatfunc() which has a large stack frame and you can see
why it would have been worth it. I will admit that if you had goto
statements, that made it considerably messier. -John]

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

<23-01-033@comp.compilers>

 copy mid

https://www.novabbs.com/devel/article-flat.php?id=660&group=comp.compilers#660

 copy link   Newsgroups: comp.compilers
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!news.iecc.com!.POSTED.news.iecc.com!nerds-end
From: david.br...@hesbynett.no (David Brown)
Newsgroups: comp.compilers
Subject: Re: another C-like language? was Compilers :)
Date: Tue, 10 Jan 2023 17:48:18 +0100
Organization: A noiseless patient Spider
Sender: news@iecc.com
Approved: comp.compilers@iecc.com
Message-ID: <23-01-033@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>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Info: gal.iecc.com; posting-host="news.iecc.com:2001:470:1f07:1126:0:676f:7373:6970";
logging-data="82433"; mail-complaints-to="abuse@iecc.com"
Keywords: design
Posted-Date: 10 Jan 2023 17:16:27 EST
X-submission-address: compilers@iecc.com
X-moderator-address: compilers-request@iecc.com
X-FAQ-and-archives: http://compilers.iecc.com
Content-Language: en-GB
In-Reply-To: <23-01-029@comp.compilers>
 by: David Brown - Tue, 10 Jan 2023 16:48 UTC

On 09/01/2023 18: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]
>
> The "Variables at the top" meme may be something coming from Pascal.
> IIRC, in Pascal, compound statements aren't full blocks; they cannot
> have VAR declarations.

I suspect it is much older than that - in assembly programming, you do
not normally mix data and code sections.

> When programmers abandoned Pascal in the 1980s, they carried over this
> habit into C.
>
> I hate mixed declarations and code because it's almost as bad as
> variables-at-the-top. The scope of a declaration that is just planted
> into the middle of a compound statement block extends all the way to the
> end of the block. There should be a smaller enclosing block which
> exactly delimits the scope of that variable. If some variable is used
> over seven lines of a 300 line function, those seven lines should
> ideally be enclosed in curly braces, so the variable is not known
> outside of those lines. Just planting an unwrapped declaration of the
> variable at the function scope level (outermost block) solves only half
> the problem. The scope of the variable starts close to where the
> variable is used, which is good; but it still goes to the end of the
> function, way past its actual semantic scope that ends at the last use.

If your variable is only used in 7 lines out of a 300 line function,
then perhaps your function is too long?

I agree that small scopes for variables are good, and put declarations
within compound statement blocks where practical (though I rarely make a
new block simply to hold a variable). But that is not the sole purpose
of mixing code and declarations - it is not even the major purpose, IMHO.

The point is that you do not declare a variable until you actually have
something to put in it. You never have this semi-alive object floating
around where it is accessible, but has no valid or known state. You
never have an artificial initialisation, such as putting 0 in a variable
declared at the top of the function, in the mistaken believe that it
makes code somehow "safer". You can make your variables "const" if they
do not change. If you are using C++ (or other object-oriented
language), you avoid the inefficiency of default-constructing an object
and later assigning to it, instead of doing a single initialisation.

Of course this applies just as well to variables defined inside blocks
as to variables defined after code.

> A block like this can be repeated with copy and paste:
>
> {
> int yes = 1;
> setsockopt(fd, SO_WHATEVER, &yes);
> }
>
> This cannot: you will get redefinition errors:
>
> int yes = 1;
> setsockopt(fd, SO_WHATEVER, &yes);
>
> you have to think about ensuring that "int yes" occurs in one place
> that is before the first use, and the other places assign to it.
> Or invent different names.
>

This is something that I would prefer C and C++ to allow. I think it
would improve the structure of some of my code, precisely as you describe.

I'd also like to be able to write :

int x = 10;
x += 20;
const int x = x; // Fix x - after this, x is constant

I wonder if anyone has made a proposal for adding this feature to C or C++ ?
[Variables at the top probably comes from Algol60 via Pascal. For assembler,
depends on the assembler. Lots of them let you have several sections in the
program and switch between the code and data sections as you go. IBM mainframe
assemblers had this feature in the 1960s. -John]

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

<23-01-034@comp.compilers>

 copy mid

https://www.novabbs.com/devel/article-flat.php?id=661&group=comp.compilers#661

 copy link   Newsgroups: comp.compilers
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!news.iecc.com!.POSTED.news.iecc.com!nerds-end
From: gah...@u.washington.edu (gah4)
Newsgroups: comp.compilers
Subject: Re: another C-like language? was Compilers :)
Date: Tue, 10 Jan 2023 15:13:33 -0800 (PST)
Organization: Compilers Central
Sender: news@iecc.com
Approved: comp.compilers@iecc.com
Message-ID: <23-01-034@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-033@comp.compilers>
MIME-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
Injection-Info: gal.iecc.com; posting-host="news.iecc.com:2001:470:1f07:1126:0:676f:7373:6970";
logging-data="7917"; mail-complaints-to="abuse@iecc.com"
Keywords: assembler, history, comment
Posted-Date: 10 Jan 2023 19:56:09 EST
X-submission-address: compilers@iecc.com
X-moderator-address: compilers-request@iecc.com
X-FAQ-and-archives: http://compilers.iecc.com
In-Reply-To: <23-01-033@comp.compilers>
 by: gah4 - Tue, 10 Jan 2023 23:13 UTC

On Tuesday, January 10, 2023 at 2:16:32 PM UTC-8, David Brown wrote:

(snip)
> The point is that you do not declare a variable until you actually have
> something to put in it. You never have this semi-alive object floating
> around where it is accessible, but has no valid or known state. You
> never have an artificial initialisation, such as putting 0 in a variable
> declared at the top of the function, in the mistaken believe that it
> makes code somehow "safer".

Java requires that the compiler be able to figure out that a variable
(well, scalar variable) is given a value before it is used. Most of the
time, that works out fine. Once in a while, I know that it is given
a value, but the compiler doesn't. In that case, it is initialized
to (usually) 0, and a comment indicating why.

(snip)

> [Variables at the top probably comes from Algol60 via Pascal. For assembler,
> depends on the assembler. Lots of them let you have several sections in the
> program and switch between the code and data sections as you go. IBM mainframe
> assemblers had this feature in the 1960s. -John]

Most of the IBM mainframe assembly code I know, puts the variables
at the bottom.

Well, early on I started reading the generated code from compilers,
and not so much later, the Fortran G&H library. Maybe not the best
examples of structured code, though.

Well, if by data section you mean DSECT, I suppose.
Most I knew didn't do much of that, though.

Variables at the bottom, and use the same base register for
code and data. You could put the variables at the top, and
branch around them. I don't remember anyone doing that.

More recent processors, maybe from ESA/390 days, have
data and instruction cache, and want data and instructions
more than (if I remember) 256 bytes apart.

But okay, it is completely different for reentrant programs,
than the static allocation non-reentrant code of much of
OS/360 associated programs.
[For IBM assember, I meant that you could have one CSECT for
your code and another for your data, and you could switch
between them as you go along. For the elite few of us who
used TSS/360, a PSECT let you set the initial contents of
the RW data that the RO code in a routine used. DSECT was
somehing else, more like a structure definition. I realize
that in practice most code was not reentrant and you put
all your code and data in one section. -John]

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

<23-01-037@comp.compilers>

 copy mid

https://www.novabbs.com/devel/article-flat.php?id=664&group=comp.compilers#664

 copy link   Newsgroups: comp.compilers
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!news.iecc.com!.POSTED.news.iecc.com!nerds-end
From: tkoe...@netcologne.de (Thomas Koenig)
Newsgroups: comp.compilers
Subject: Re: another C-like language? was Compilers :)
Date: Wed, 11 Jan 2023 10:49:15 -0000 (UTC)
Organization: news.netcologne.de
Sender: news@iecc.com
Approved: comp.compilers@iecc.com
Message-ID: <23-01-037@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>
Injection-Info: gal.iecc.com; posting-host="news.iecc.com:2001:470:1f07:1126:0:676f:7373:6970";
logging-data="93956"; mail-complaints-to="abuse@iecc.com"
Keywords: C, history
Posted-Date: 11 Jan 2023 18:07:30 EST
X-submission-address: compilers@iecc.com
X-moderator-address: compilers-request@iecc.com
X-FAQ-and-archives: http://compilers.iecc.com
 by: Thomas Koenig - Wed, 11 Jan 2023 10:49 UTC

Kaz Kylheku <864-117-4973@kylheku.com> schrieb:

> The "Variables at the top" meme may be something coming from Pascal.
> IIRC, in Pascal, compound statements aren't full blocks; they cannot
> have VAR declarations.

FORTRAN has had declaration statements (first version, DIMENSION
only) at the top of procedures since the beginning. Algol 58
aka IAL had declarations everywere, while Algol 60 allowed them
only at the beginning of blocks.

> When programmers abandoned Pascal in the 1980s, they carried over this
> habit into C.

Probably, C just carried it over from the Algol tradition.

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

<23-01-038@comp.compilers>

 copy mid

https://www.novabbs.com/devel/article-flat.php?id=665&group=comp.compilers#665

 copy link   Newsgroups: comp.compilers
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!news.iecc.com!.POSTED.news.iecc.com!nerds-end
From: 864-117-...@kylheku.com (Kaz Kylheku)
Newsgroups: comp.compilers
Subject: Re: another C-like language? was Compilers :)
Date: Wed, 11 Jan 2023 11:02:56 -0000 (UTC)
Organization: A noiseless patient Spider
Sender: news@iecc.com
Approved: comp.compilers@iecc.com
Message-ID: <23-01-038@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-033@comp.compilers>
Injection-Info: gal.iecc.com; posting-host="news.iecc.com:2001:470:1f07:1126:0:676f:7373:6970";
logging-data="94550"; mail-complaints-to="abuse@iecc.com"
Keywords: C, design
Posted-Date: 11 Jan 2023 18:09:11 EST
X-submission-address: compilers@iecc.com
X-moderator-address: compilers-request@iecc.com
X-FAQ-and-archives: http://compilers.iecc.com
 by: Kaz Kylheku - Wed, 11 Jan 2023 11:02 UTC

On 2023-01-10, David Brown <david.brown@hesbynett.no> wrote:
> On 09/01/2023 18:41, Kaz Kylheku wrote:
>> On 2023-01-06, David Brown <david.brown@hesbynett.no> wrote:
>> A block like this can be repeated with copy and paste:
>>
>> {
>> int yes = 1;
>> setsockopt(fd, SO_WHATEVER, &yes);
>> }
>>
>> This cannot: you will get redefinition errors:
>>
>> int yes = 1;
>> setsockopt(fd, SO_WHATEVER, &yes);
>>
>> you have to think about ensuring that "int yes" occurs in one place
>> that is before the first use, and the other places assign to it.
>> Or invent different names.
>
> This is something that I would prefer C and C++ to allow. I think it
> would improve the structure of some of my code, precisely as you describe.

It seems that Scheme, with its ugly (define ...) that can be used inside
block scopes, has the same restriction!

I tried (lambda () (define x 42) (define x 43)) in a Scheme
implementation and got an error about the duplicate variable.

That's completely silly since it breaks the idea that the block scoped
define can just be desugared to nested lets.

On a related topic, the CLISP implementation of Common Lisp, whose
history goes back to the 1980s, availed itself of mixing variable
declarations and statements even in C90. Its source files are named with
a .d suffix, and are preproced by a "varbrace" tool which spits out
the brace-enclosed blocks. I seem to recall that variables are prefixed
with a "var" specifier, which probably makes it easy for the tool to
recognize declarations.

It may likely be the case that under CLISP's "varbrace" you can repeat
variable names.

.... and searching for varbrace, I see a 2017 thread in the CLISP
mailing list by someone who posted a patch to rid CLISP of varbrace,
and just use C99. The patch submmitter mentions that he had to rename
some instances of repeated variables, making this remark:

Another issue is conflicting definitions of the same variable. Example:

var type1 foo;
// some code
var type2 foo;

This is solved by renaming one of them, if possible. In two places, I
manually added braces (like varbrace would've done)

--
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
Mastodon: @Kazinator@mstdn.ca

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

<23-01-039@comp.compilers>

 copy mid

https://www.novabbs.com/devel/article-flat.php?id=666&group=comp.compilers#666

 copy link   Newsgroups: comp.compilers
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!news.iecc.com!.POSTED.news.iecc.com!nerds-end
From: findlayb...@blueyonder.co.uk (Bill Findlay)
Newsgroups: comp.compilers
Subject: Re: another C-like language? was Compilers :)
Date: Wed, 11 Jan 2023 11:58:52 +0000
Organization: none
Sender: news@iecc.com
Approved: comp.compilers@iecc.com
Message-ID: <23-01-039@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-033@comp.compilers>
Reply-To: findlaybill@blueyonder.co.uk
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 8bit
Injection-Info: gal.iecc.com; posting-host="news.iecc.com:2001:470:1f07:1126:0:676f:7373:6970";
logging-data="94918"; mail-complaints-to="abuse@iecc.com"
Keywords: C, history
Posted-Date: 11 Jan 2023 18:09:40 EST
X-submission-address: compilers@iecc.com
X-moderator-address: compilers-request@iecc.com
X-FAQ-and-archives: http://compilers.iecc.com
 by: Bill Findlay - Wed, 11 Jan 2023 11:58 UTC

On 10 Jan 2023, David Brown wrote
(in article <23-01-033@comp.compilers>):

> [Variables at the top probably comes from Algol60 via Pascal. ... -John]

And via Algol 60 from FORTRAN.

--
Bill Findlay

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

<23-01-040@comp.compilers>

 copy mid

https://www.novabbs.com/devel/article-flat.php?id=667&group=comp.compilers#667

 copy link   Newsgroups: comp.compilers
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!news.iecc.com!.POSTED.news.iecc.com!nerds-end
From: david.br...@hesbynett.no (David Brown)
Newsgroups: comp.compilers
Subject: Re: another C-like language? was Compilers :)
Date: Wed, 11 Jan 2023 13:38:09 +0100
Organization: A noiseless patient Spider
Sender: news@iecc.com
Approved: comp.compilers@iecc.com
Message-ID: <23-01-040@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-033@comp.compilers> <23-01-034@comp.compilers>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Info: gal.iecc.com; posting-host="news.iecc.com:2001:470:1f07:1126:0:676f:7373:6970";
logging-data="95332"; mail-complaints-to="abuse@iecc.com"
Keywords: C, standards
Posted-Date: 11 Jan 2023 18:10:35 EST
X-submission-address: compilers@iecc.com
X-moderator-address: compilers-request@iecc.com
X-FAQ-and-archives: http://compilers.iecc.com
Content-Language: en-GB
In-Reply-To: <23-01-034@comp.compilers>
 by: David Brown - Wed, 11 Jan 2023 12:38 UTC

On 11/01/2023 00:13, gah4 wrote:
> On Tuesday, January 10, 2023 at 2:16:32 PM UTC-8, David Brown wrote:
>
> (snip)
>> The point is that you do not declare a variable until you actually have
>> something to put in it. You never have this semi-alive object floating
>> around where it is accessible, but has no valid or known state. You
>> never have an artificial initialisation, such as putting 0 in a variable
>> declared at the top of the function, in the mistaken believe that it
>> makes code somehow "safer".
>
> Java requires that the compiler be able to figure out that a variable
> (well, scalar variable) is given a value before it is used. Most of the
> time, that works out fine. Once in a while, I know that it is given
> a value, but the compiler doesn't. In that case, it is initialized
> to (usually) 0, and a comment indicating why.
>

The same applies to C and C++ programming, when using static error
checking. (And during development, you should definitely be using a
compiler capable of spotting missing initialisations, and you should
treat such warnings as bugs in your code.) And like Java tools, C and
C++ compilers are not /quite/ perfect :-)

So I agree that there are occasional uses for such "artificial"
initialisation. There are also occasions when declaring a variable
without initialising makes sense because you will later set its value
inside a conditional.

But in general, declaring and initialising at the same time is better
(IMHO). And artificial zero initialisation is a bad thing, precisely
because it effectively disables the kind of warning checks you get in
Java and in C/C++ with an appropriate compiler or linter.

> (snip)
>
>> [Variables at the top probably comes from Algol60 via Pascal. For assembler,
>> depends on the assembler. Lots of them let you have several sections in the
>> program and switch between the code and data sections as you go. IBM mainframe
>> assemblers had this feature in the 1960s. -John]
>
> Most of the IBM mainframe assembly code I know, puts the variables
> at the bottom.

That's new to me - but I have no experience with mainframes. In all the
assembly I have done (lots of different microcontrollers), I have always
had the data declared before the code that uses them. I've alternated
between data and code sections, but not within functions.

But maybe this is because most of the small microcontrollers I
programmed were pretty hopeless at dealing with data on a stack, and it
was normal to put local variables in data sections - you have static
addressing, rather than through base pointers or frame pointers. It is
quite different from how you work with "big" processors - even in the
days when the "big" processors were slower and had less memory than
modern "small" processors, if you understand what I mean.

Thanks for the history titbits here. It's always fun to hear about.

Re: back in the 60s, another C-like language? was Compilers :)

<23-01-044@comp.compilers>

 copy mid

https://www.novabbs.com/devel/article-flat.php?id=671&group=comp.compilers#671

 copy link   Newsgroups: comp.compilers
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!news.iecc.com!.POSTED.news.iecc.com!nerds-end
From: gah...@u.washington.edu (gah4)
Newsgroups: comp.compilers
Subject: Re: back in the 60s, another C-like language? was Compilers :)
Date: Wed, 11 Jan 2023 16:38:32 -0800 (PST)
Organization: Compilers Central
Sender: news@iecc.com
Approved: comp.compilers@iecc.com
Message-ID: <23-01-044@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-033@comp.compilers> <23-01-034@comp.compilers> <23-01-040@comp.compilers>
MIME-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
Injection-Info: gal.iecc.com; posting-host="news.iecc.com:2001:470:1f07:1126:0:676f:7373:6970";
logging-data="35532"; mail-complaints-to="abuse@iecc.com"
Keywords: code, history
Posted-Date: 11 Jan 2023 22:25:48 EST
X-submission-address: compilers@iecc.com
X-moderator-address: compilers-request@iecc.com
X-FAQ-and-archives: http://compilers.iecc.com
In-Reply-To: <23-01-040@comp.compilers>
 by: gah4 - Thu, 12 Jan 2023 00:38 UTC

On Wednesday, January 11, 2023 at 3:10:38 PM UTC-8, David Brown wrote:

(snip, I wrote)
> > Java requires that the compiler be able to figure out that a variable
> > (well, scalar variable) is given a value before it is used.

(snip)
> The same applies to C and C++ programming, when using static error
> checking. (And during development, you should definitely be using a
> compiler capable of spotting missing initialisations, and you should
> treat such warnings as bugs in your code.) And like Java tools, C and
> C++ compilers are not /quite/ perfect :-)

As well as I know it, this isn't optional in Java.

> So I agree that there are occasional uses for such "artificial"
> initialisation. There are also occasions when declaring a variable
> without initialising makes sense because you will later set its value
> inside a conditional.

(snip)
> >> [Variables at the top probably comes from Algol60 via Pascal. For assembler,
> >> depends on the assembler. Lots of them let you have several sections in the
> >> program and switch between the code and data sections as you go. IBM mainframe
> >> assemblers had this feature in the 1960s. -John]

I remember knowing that, but rarely seeing it. In high school years, I would
read IBM manuals, and so knew many things that I would never use.

And since each card of the object program has its address, and which CSECT
it belongs to, the linker can figure it all out.

> > Most of the IBM mainframe assembly code I know, puts the variables
> > at the bottom.

> That's new to me - but I have no experience with mainframes. In all the
> assembly I have done (lots of different microcontrollers), I have always
> had the data declared before the code that uses them. I've alternated
> between data and code sections, but not within functions.

If you allow forward references for code (that is, forward jumps),
you can also have forward references for data.

Well, this all works if you have (at least) a two pass assembler.
Find the address of everything the first time through, and then
generate code on the second pass.

> But maybe this is because most of the small microcontrollers I
> programmed were pretty hopeless at dealing with data on a stack, and it
> was normal to put local variables in data sections - you have static
> addressing, rather than through base pointers or frame pointers. It is
> quite different from how you work with "big" processors - even in the
> days when the "big" processors were slower and had less memory than
> modern "small" processors, if you understand what I mean.

I am now remembering that the early IBM Fortran compilers put code
at the bottom of address space, and data at the top, going down.

One early Fortran feature that got removed later, is the ability to chain.
One (whole) program can chain to another, which then replaces it
in memory, but with all COMMON variables still there.

I suspect that this was replaced by overlay, which is a better
solution to the problem. It might be that, which led to putting
data after code.

Another one is that with base-displacement addressing, you only
need to be able to address the beginning of an array. Putting large
arrays at the end, then, makes it easier.

That is also the way Fortran code generators did it for OS/360.
(Static addressed with code and data together.)

Early microcomputer assemblers might not have been as good,
though as well as I know it, Microsoft used the PDP-10 assembler
from the beginning.

A favorite way to write microcomputer assembly code, is with
macros on a mainframe assembler, one for each instruction.
All the hard work is then done by the assembler itself.

Re: Scheme is not another C-like language? was Compilers :)

<23-01-046@comp.compilers>

 copy mid

https://www.novabbs.com/devel/article-flat.php?id=673&group=comp.compilers#673

 copy link   Newsgroups: comp.compilers
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!news.iecc.com!.POSTED.news.iecc.com!nerds-end
From: gneun...@comcast.net (George Neuner)
Newsgroups: comp.compilers
Subject: Re: Scheme is not another C-like language? was Compilers :)
Date: Thu, 12 Jan 2023 02:54:37 -0500
Organization: A noiseless patient Spider
Sender: news@iecc.com
Approved: comp.compilers@iecc.com
Message-ID: <23-01-046@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-033@comp.compilers> <23-01-038@comp.compilers>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
Injection-Info: gal.iecc.com; posting-host="news.iecc.com:2001:470:1f07:1126:0:676f:7373:6970";
logging-data="12037"; mail-complaints-to="abuse@iecc.com"
Keywords: Scheme
Posted-Date: 12 Jan 2023 13:38:52 EST
X-submission-address: compilers@iecc.com
X-moderator-address: compilers-request@iecc.com
X-FAQ-and-archives: http://compilers.iecc.com
 by: George Neuner - Thu, 12 Jan 2023 07:54 UTC

On Wed, 11 Jan 2023 11:02:56 -0000 (UTC), Kaz Kylheku
<864-117-4973@kylheku.com> wrote:

>It seems that Scheme, with its ugly (define ...) that can be used inside
>block scopes, [disallows name redefinition]!

Agree it's ugly: I never use internal defines in my own code.
Unfortunately some people love them.

>I tried (lambda () (define x 42) (define x 43)) in a Scheme
>implementation and got an error about the duplicate variable.
>
>That's completely silly since it breaks the idea that the block scoped
>define can just be desugared to nested lets.

Unfortunately the experience varies by version:

From R3RS to R5RS, a series of internal defines is treated AS IF they
all are part of a single 'letrec' with the scope being the whole body.
'letrec', of course, does not permit multiple bindings to the same
name.

In R6RS and R7RS, a series of internal defines is treated as a
'letrec*' [note trailing *]. letrec* is equivalent to nested letrec
and so does permit rebinding to the same name ... which will shadow
any previous bindings.

from R5RS 5.2.2 Internal Definitions

.... The variable defined by an internal defnition is local to the
body. That is, variable is bound rather than assigned, and the region
of the binding is the entire body. For example,

(let ((x 5))
(define foo (lambda (y) (bar x y)))
(define bar (lambda (a b) (+ (* a b) a)))
(foo (+ x 3))) => 45

A body containing internal definitions can always be converted into a
completely equivalent letrec expression. For example, the let
expression in the above example is equivalent to

(let ((x 5))
(letrec ((foo (lambda (y) (bar x y)))
(bar (lambda (a b) (+ (* a b) a))))
(foo (+ x 3))))

Just as for the equivalent letrec expression, it must be possible to
evaluate each expression of every internal definition in a body
without assigning or referring to the value of any variable being
defined.

From R6RS 11.3 Bodies

The <body> of a lambda, let, let*, let-values, let*-values, letrec, or
letrec* expression, or that of a definition with a body consists of
zero or more definitions followed by one or more expressions.

<definition> ... <expression1> <expression2> ...

Each identifier defined by a definition is local to the <body>. That
is, the identifier is bound, and the region of the binding is the
entire <body> (see section [5.2]).

Example:

(let ((x 5))
  (define foo (lambda (y) (bar x y)))
  (define bar (lambda (a b) (+ (* a b) a)))
  (foo (+ x 3)))               =>  45

When begin, let-syntax, or letrec-syntax forms occur in a body prior
to the first expression, they are spliced into the body; see
section [11.4.7]. Some or all of the body, including portions wrapped
in begin, let-syntax, or letrec-syntax forms, may be specified by a
macro use (see section [9.2]).

An expanded <body> (see chapter [10]) containing variable definitions
can always be converted into an equivalent letrec* expression. For
example, the let expression in the above example is equivalent to

(let ((x 5))
  (letrec* ((foo (lambda (y) (bar x y)))
            (bar (lambda (a b) (+ (\* a b) a))))
    (foo (+ x 3))))

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

<23-01-052@comp.compilers>

 copy mid

https://www.novabbs.com/devel/article-flat.php?id=679&group=comp.compilers#679

 copy link   Newsgroups: comp.compilers
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!news.iecc.com!.POSTED.news.iecc.com!nerds-end
From: lagu...@archeia.com (Luke A. Guest)
Newsgroups: comp.compilers
Subject: Re: another C-like language? was Compilers :)
Date: Fri, 13 Jan 2023 18:25:37 +0000
Organization: Aioe.org NNTP Server
Sender: news@iecc.com
Approved: comp.compilers@iecc.com
Message-ID: <23-01-052@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>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Info: gal.iecc.com; posting-host="news.iecc.com:2001:470:1f07:1126:0:676f:7373:6970";
logging-data="95524"; mail-complaints-to="abuse@iecc.com"
Keywords: C, standards
Posted-Date: 13 Jan 2023 14:09:25 EST
X-submission-address: compilers@iecc.com
X-moderator-address: compilers-request@iecc.com
X-FAQ-and-archives: http://compilers.iecc.com
Content-Language: en-GB
 by: Luke A. Guest - Fri, 13 Jan 2023 18:25 UTC

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.

> 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.

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

<23-01-056@comp.compilers>

 copy mid

https://www.novabbs.com/devel/article-flat.php?id=683&group=comp.compilers#683

 copy link   Newsgroups: comp.compilers
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!news.iecc.com!.POSTED.news.iecc.com!nerds-end
From: gneun...@comcast.net (George Neuner)
Newsgroups: comp.compilers
Subject: Re: another C-like language? was Compilers :)
Date: Fri, 13 Jan 2023 17:20:35 -0500
Organization: A noiseless patient Spider
Sender: news@iecc.com
Approved: comp.compilers@iecc.com
Message-ID: <23-01-056@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>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 8bit
Injection-Info: gal.iecc.com; posting-host="news.iecc.com:2001:470:1f07:1126:0:676f:7373:6970";
logging-data="36458"; mail-complaints-to="abuse@iecc.com"
Keywords: C, history, comment
Posted-Date: 13 Jan 2023 17:30:20 EST
X-submission-address: compilers@iecc.com
X-moderator-address: compilers-request@iecc.com
X-FAQ-and-archives: http://compilers.iecc.com
 by: George Neuner - Fri, 13 Jan 2023 22:20 UTC

On Fri, 13 Jan 2023 18:25:37 +0000, "Luke A. Guest"
<laguest@archeia.com> wrote:

> C is an Algol derived language.

Well ... Algol influenced in any case, through B.
[Rather indirectly. C is derived from B which was a
stripped down version of BCPL which was a boostrap
subset of CPL which was designed in the early 1960s
with influence from Algol. See Wikipedia. -John]

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

<23-01-057@comp.compilers>

 copy mid

https://www.novabbs.com/devel/article-flat.php?id=684&group=comp.compilers#684

 copy link   Newsgroups: comp.compilers
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!news.iecc.com!.POSTED.news.iecc.com!nerds-end
From: 864-117-...@kylheku.com (Kaz Kylheku)
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
 by: Kaz Kylheku - Sat, 14 Jan 2023 19:07 UTC

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]

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

<23-01-059@comp.compilers>

 copy mid

https://www.novabbs.com/devel/article-flat.php?id=686&group=comp.compilers#686

 copy link   Newsgroups: comp.compilers
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!news.iecc.com!.POSTED.news.iecc.com!nerds-end
From: marbly...@yahoo.co.uk (marb...@yahoo.co.uk)
Newsgroups: comp.compilers
Subject: Re: another C-like language? was Compilers :)
Date: Sun, 15 Jan 2023 04:21:52 -0800 (PST)
Organization: Compilers Central
Sender: news@iecc.com
Approved: comp.compilers@iecc.com
Message-ID: <23-01-059@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-037@comp.compilers>
MIME-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
Injection-Info: gal.iecc.com; posting-host="news.iecc.com:2001:470:1f07:1126:0:676f:7373:6970";
logging-data="38945"; mail-complaints-to="abuse@iecc.com"
Keywords: algol68, history
Posted-Date: 15 Jan 2023 13:10:36 EST
X-submission-address: compilers@iecc.com
X-moderator-address: compilers-request@iecc.com
X-FAQ-and-archives: http://compilers.iecc.com
In-Reply-To: <23-01-037@comp.compilers>
 by: marb...@yahoo.co.uk - Sun, 15 Jan 2023 12:21 UTC

On Wednesday, 11 January 2023 at 23:07:33 UTC, Thomas Koenig wrote:
> Algol 58
> aka IAL had declarations everywere, while Algol 60 allowed them
> only at the beginning of blocks.

But Algol 68 allows them anywhere:

INT x:=42;
print(("x=",x,newline));
INT y:=76;
print(("y=",y,newline));
x:=y:=101;
print(("x=",x,newline,"y=",y,newline))

(There's something a bit weird about it in A68, though, but I can't remember what.)
(I tend to think of A68 as "A60 made perfect... then some dubious
features are added". I gather it took 6 years to write the first
complete A68 compiler! Well, strictly speaking, they'd revised A68 by
then, so it was an A68R compiler.)

Pages:12
server_pubkey.txt

rocksolid light 0.9.7
clearnet tor