Groups | Search | Server Info | Keyboard shortcuts | Login | Register
Groups > comp.compilers > #3292
| Path | csiph.com!weretis.net!feeder6.news.weretis.net!news.misty.com!news.iecc.com!.POSTED.news.iecc.com!nerds-end |
|---|---|
| From | David Brown <david.brown@hesbynett.no> |
| 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> (permalink) |
| 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> |
| Xref | csiph.com comp.compilers:3292 |
Show key headers only | View raw
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]
Back to comp.compilers | Previous | Next — Previous in thread | Next in thread | Find similar
Compilers :) "Tristan B. Velloza Kildaire" <deavmi@redxen.eu> - 2023-01-02 12:28 +0200
Re: Compilers :) Spiros Bousbouras <spibou@gmail.com> - 2023-01-02 20:52 +0000
Re: another C-like language? was Compilers :) Steve Limb <stephenjohnlimb@gmail.com> - 2023-01-03 16:24 +0000
Re: another C-like language? was Compilers :) gah4 <gah4@u.washington.edu> - 2023-01-03 12:52 -0800
Re: another C-like language? was Compilers :) arnold@skeeve.com (Aharon Robbins) - 2023-01-04 17:12 +0000
Re: another C-like language? was Compilers :) gah4 <gah4@u.washington.edu> - 2023-01-04 12:39 -0800
Re: another C-like language? was Compilers :) "marb...@yahoo.co.uk" <marblypup@yahoo.co.uk> - 2023-01-05 06:27 -0800
Re: another C-like language? was Compilers :) gah4 <gah4@u.washington.edu> - 2023-01-05 16:26 -0800
Re: another C-like language? was Compilers :) David Brown <david.brown@hesbynett.no> - 2023-01-06 15:39 +0100
Re: another C-like language? was Compilers :) Kaz Kylheku <864-117-4973@kylheku.com> - 2023-01-09 17:41 +0000
Re: another C-like language? was Compilers :) David Brown <david.brown@hesbynett.no> - 2023-01-10 17:48 +0100
Re: another C-like language? was Compilers :) gah4 <gah4@u.washington.edu> - 2023-01-10 15:13 -0800
Re: another C-like language? was Compilers :) David Brown <david.brown@hesbynett.no> - 2023-01-11 13:38 +0100
Re: back in the 60s, another C-like language? was Compilers :) gah4 <gah4@u.washington.edu> - 2023-01-11 16:38 -0800
Re: another C-like language? was Compilers :) "marb...@yahoo.co.uk" <marblypup@yahoo.co.uk> - 2023-01-15 04:26 -0800
Re: another C-like language? was Compilers :) Kaz Kylheku <864-117-4973@kylheku.com> - 2023-01-11 11:02 +0000
Re: Scheme is not another C-like language? was Compilers :) George Neuner <gneuner2@comcast.net> - 2023-01-12 02:54 -0500
Re: another C-like language? was Compilers :) Bill Findlay <findlaybill@blueyonder.co.uk> - 2023-01-11 11:58 +0000
Re: another C-like language? was Compilers :) Thomas Koenig <tkoenig@netcologne.de> - 2023-01-11 10:49 +0000
Re: another C-like language? was Compilers :) "marb...@yahoo.co.uk" <marblypup@yahoo.co.uk> - 2023-01-15 04:21 -0800
Re: another C-like language? was Compilers :) Andy Walker <anw@cuboid.co.uk> - 2023-01-15 22:01 +0000
Re: another C-like language? was Compilers :) "Luke A. Guest" <laguest@archeia.com> - 2023-01-13 18:25 +0000
Re: another C-like language? was Compilers :) George Neuner <gneuner2@comcast.net> - 2023-01-13 17:20 -0500
Re: another C-like language? was Compilers :) Kaz Kylheku <864-117-4973@kylheku.com> - 2023-01-14 19:07 +0000
Re: another C-like language? was Compilers :) "marb...@yahoo.co.uk" <marblypup@yahoo.co.uk> - 2023-01-07 02:14 -0800
Re: another C-like language? was Compilers :) David Brown <david.brown@hesbynett.no> - 2023-01-08 20:21 +0100
Re: another C-like language? was Compilers :) Hans-Peter Diettrich <DrDiettrich1@netscape.net> - 2023-01-09 04:48 +0100
Re: C scopes, another C-like language? was Compilers :) David Brown <david.brown@hesbynett.no> - 2023-01-09 18:12 +0100
Re: another C-like language? was Compilers :) Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2023-01-09 11:24 -0800
Re: Compilers :) "Tristan B. Velloza Kildaire" <deavmi@redxen.eu> - 2023-01-13 13:41 +0200
Re: Compilers :) Hans-Peter Diettrich <DrDiettrich1@netscape.net> - 2023-01-05 01:12 +0100
Re: Compilers :) "Tristan B. Velloza Kildaire" <deavmi@redxen.eu> - 2023-01-13 14:17 +0200
Re: C and Java, was Compilers :) gah4 <gah4@u.washington.edu> - 2023-01-13 10:32 -0800
Re: C and Java, was Compilers :) gah4 <gah4@u.washington.edu> - 2023-01-13 12:39 -0800
Re: C and Java, was Compilers :) dave_thompson_2@comcast.net - 2023-01-28 10:37 -0500
Re: C and archtecture, C and Java, was Compilers :) Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2023-01-29 19:37 -0800
Re: C and Java, was Compilers :) gah4 <gah4@u.washington.edu> - 2023-01-29 21:39 -0800
csiph-web