Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c > #160277 > unrolled thread
| Started by | jacobnavia <jacob@jacob.remcomp.fr> |
|---|---|
| First post | 2021-04-22 18:58 +0200 |
| Last post | 2021-04-26 18:04 +0200 |
| Articles | 18 on this page of 78 — 23 participants |
Back to article view | Back to comp.lang.c
Text editor project in C jacobnavia <jacob@jacob.remcomp.fr> - 2021-04-22 18:58 +0200
Re: Text editor project in C Bonita Montero <Bonita.Montero@gmail.com> - 2021-04-22 19:05 +0200
Re: Text editor project in C steveh <steveh@nospam.invalid> - 2021-04-22 19:31 +0000
Re: Text editor project in C Bonita Montero <Bonita.Montero@gmail.com> - 2021-04-23 19:25 +0200
Re: Text editor project in C Oğuz <oguzismailuysal@gmail.com> - 2021-04-23 12:21 -0700
Re: Text editor project in C Bonita Montero <Bonita.Montero@gmail.com> - 2021-04-24 05:10 +0200
Re: Text editor project in C Juha Nieminen <nospam@thanks.invalid> - 2021-04-23 07:55 +0000
Re: Text editor project in C jacobnavia <jacob@jacob.remcomp.fr> - 2021-04-23 11:25 +0200
Re: Text editor project in C silas poulson <Silas8642@hotmail.co.uk> - 2021-04-23 07:32 -0700
Re: Text editor project in C "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2021-04-23 12:45 -0700
Re: Text editor project in C jacobnavia <jacob@jacob.remcomp.fr> - 2021-04-23 22:29 +0200
Re: Text editor project in C "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2021-04-23 13:34 -0700
Re: Text editor project in C "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2021-04-23 13:37 -0700
Re: Text editor project in C jacobnavia <jacob@jacob.remcomp.fr> - 2021-04-23 22:40 +0200
Re: Text editor project in C "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2021-04-23 13:51 -0700
Re: Text editor project in C "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2021-04-23 13:55 -0700
Re: Text editor project in C jacobnavia <jacob@jacob.remcomp.fr> - 2021-04-23 23:02 +0200
Re: Text editor project in C "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2021-04-23 14:13 -0700
Re: Text editor project in C "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2021-04-23 15:39 -0700
Re: Text editor project in C Bart <bc@freeuk.com> - 2021-04-24 01:20 +0100
Re: Text editor project in C "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2021-04-23 17:43 -0700
Re: Text editor project in C kegs@provalid.com (Kent Dickey) - 2021-04-25 00:04 -0500
Re: Text editor project in C "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2021-04-24 22:29 -0700
Re: Text editor project in C "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2021-04-24 23:05 -0700
Re: Text editor project in C Paavo Helde <myfirstname@osa.pri.ee> - 2021-04-25 10:57 +0300
Re: Text editor project in C "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2021-04-25 01:18 -0700
Re: Text editor project in C Paavo Helde <myfirstname@osa.pri.ee> - 2021-04-25 11:28 +0300
Re: Text editor project in C James Kuyper <jameskuyper@alumni.caltech.edu> - 2021-04-25 15:02 -0400
Re: Text editor project in C "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2021-04-26 01:25 -0700
Re: Text editor project in C "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2021-04-26 01:26 -0700
Re: Text editor project in C "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2021-04-23 14:15 -0700
Re: Text editor project in C scott@slp53.sl.home (Scott Lurndal) - 2021-04-23 22:25 +0000
Re: Text editor project in C "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2021-04-23 15:31 -0700
Re: Text editor project in C "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2021-04-23 13:38 -0700
Re: Text editor project in C scott@slp53.sl.home (Scott Lurndal) - 2021-04-23 22:27 +0000
Re: Text editor project in C "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2021-04-23 15:34 -0700
Re: Text editor project in C scott@slp53.sl.home (Scott Lurndal) - 2021-04-24 16:33 +0000
Re: Text editor project in C "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2021-04-24 22:59 -0700
Re: Text editor project in C Juha Nieminen <nospam@thanks.invalid> - 2021-04-26 05:22 +0000
Re: Text editor project in C jacobnavia <jacob@jacob.remcomp.fr> - 2021-04-26 10:00 +0200
Re: Text editor project in C Juha Nieminen <nospam@thanks.invalid> - 2021-04-26 09:57 +0000
Re: Text editor project in C Robert Latest <boblatest@yahoo.com> - 2021-04-26 10:41 +0000
Re: Text editor project in C jacobnavia <jacob@jacob.remcomp.fr> - 2021-04-26 13:20 +0200
Re: Text editor project in C Juha Nieminen <nospam@thanks.invalid> - 2021-04-26 13:17 +0000
Re: Text editor project in C jacobnavia <jacob@jacob.remcomp.fr> - 2021-04-26 19:53 +0200
Re: Text editor project in C David Brown <david.brown@hesbynett.no> - 2021-04-26 20:34 +0200
Re: Text editor project in C jacobnavia <jacob@jacob.remcomp.fr> - 2021-04-26 22:49 +0200
Re: Text editor project in C David Brown <david.brown@hesbynett.no> - 2021-04-27 10:59 +0200
Re: Text editor project in C Ben Bacarisse <ben.usenet@bsb.me.uk> - 2021-04-26 22:04 +0100
Re: Text editor project in C Eli the Bearded <*@eli.users.panix.com> - 2021-04-26 22:19 +0000
Re: Text editor project in C Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2021-04-26 16:07 -0700
Re: Text editor project in C Joe Pfeiffer <pfeiffer@cs.nmsu.edu> - 2021-04-26 17:08 -0600
Re: Text editor project in C Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2021-04-26 16:57 -0700
Re: Text editor project in C Joe Pfeiffer <pfeiffer@cs.nmsu.edu> - 2021-04-26 21:42 -0600
Re: Text editor project in C Kaz Kylheku <563-365-8930@kylheku.com> - 2021-04-27 00:46 +0000
Re: Text editor project in C Juha Nieminen <nospam@thanks.invalid> - 2021-04-27 04:51 +0000
Re: Text editor project in C Joe Pfeiffer <pfeiffer@cs.nmsu.edu> - 2021-04-27 10:03 -0600
Re: Text editor project in C Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2021-04-27 09:20 -0700
Re: Text editor project in C scott@slp53.sl.home (Scott Lurndal) - 2021-04-27 16:34 +0000
Re: Text editor project in C Joe Pfeiffer <pfeiffer@cs.nmsu.edu> - 2021-04-27 10:55 -0600
Re: Text editor project in C Kaz Kylheku <563-365-8930@kylheku.com> - 2021-04-27 17:13 +0000
Re: Text editor project in C Lew Pitcher <lew.pitcher@digitalfreehold.ca> - 2021-04-27 17:28 +0000
Re: Text editor project in C Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2021-04-27 13:33 -0700
Re: Text editor project in C scott@slp53.sl.home (Scott Lurndal) - 2021-04-27 19:27 +0000
Re: Text editor project in C Kaz Kylheku <563-365-8930@kylheku.com> - 2021-04-27 17:11 +0000
Re: Text editor project in C scott@slp53.sl.home (Scott Lurndal) - 2021-04-27 14:28 +0000
Re: Text editor project in C Juha Nieminen <nospam@thanks.invalid> - 2021-04-27 15:11 +0000
Re: Text editor project in C Ben Bacarisse <ben.usenet@bsb.me.uk> - 2021-04-26 21:37 +0100
Re: Text editor project in C jacobnavia <jacob@jacob.remcomp.fr> - 2021-04-26 22:48 +0200
Re: Text editor project in C scott@slp53.sl.home (Scott Lurndal) - 2021-04-26 21:53 +0000
Re: Text editor project in C Ben Bacarisse <ben.usenet@bsb.me.uk> - 2021-04-27 01:34 +0100
Re: Text editor project in C Guillaume <message@bottle.org> - 2021-04-26 18:48 +0200
Re: Text editor project in C James Kuyper <jameskuyper@alumni.caltech.edu> - 2021-04-26 13:54 -0400
Re: Text editor project in C Jorgen Grahn <grahn+nntp@snipabacken.se> - 2021-04-23 20:00 +0000
Re: Text editor project in C scott@slp53.sl.home (Scott Lurndal) - 2021-04-23 20:25 +0000
Re: Text editor project in C Juha Nieminen <nospam@thanks.invalid> - 2021-04-26 05:29 +0000
Re: Text editor project in C om@iki.fi (Otto J. Makela) - 2021-04-23 19:25 +0300
Re: Text editor project in C Bonita Montero <Bonita.Montero@gmail.com> - 2021-04-26 18:04 +0200
Page 4 of 4 — ← Prev page 1 2 3 [4]
| From | Kaz Kylheku <563-365-8930@kylheku.com> |
|---|---|
| Date | 2021-04-27 17:13 +0000 |
| Message-ID | <20210427101137.594@kylheku.com> |
| In reply to | #160408 |
On 2021-04-27, Joe Pfeiffer <pfeiffer@cs.nmsu.edu> wrote: > scott@slp53.sl.home (Scott Lurndal) writes: >> And, unfortunately, the types often were not abstracted behind >> a typedef. The process identifer, group identifier and user >> identifers were all 16-bit as well. This made for a painful >> conversion to 32-bit PID/GID/UID in SVR4 (accompanied by abstract >> types pid_t, gid_t, uid_t which, when used correctly, mean that >> applications only needed a simple recompile to handle a change in width). > > There were no typedefs back then (at least I don't remember them that > far back, and they don't appear in either Ritchie's reference manual nor > Kernighan's tutorial). The preprocessor was used for type definitions; that's why FILE is capitalized. #define FILE struct _iobuf or something like that. The Indian Hill naming (typedefs are all caps) that spilled into MS Windows is probably inspired by that. -- TXR Programming Language: http://nongnu.org/txr Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
[toc] | [prev] | [next] | [standalone]
| From | Lew Pitcher <lew.pitcher@digitalfreehold.ca> |
|---|---|
| Date | 2021-04-27 17:28 +0000 |
| Message-ID | <s69hkk$dmr$1@dont-email.me> |
| In reply to | #160408 |
On Tue, 27 Apr 2021 10:55:37 -0600, Joe Pfeiffer wrote:
> scott@slp53.sl.home (Scott Lurndal) writes:
>
>> Joe Pfeiffer <pfeiffer@cs.nmsu.edu> writes:
>>>Juha Nieminen <nospam@thanks.invalid> writes:
>>>
>>>> However, the undetermined size of basic types (especially before
>>>> standardization) makes it more likely for C programs, especially ones
>>>> written back then, to be non-portable. Sure, even back when K&R first
>>>> "soft-standardized" the C language you shouldn't have assumed a certain
>>>> size for any basic type.
>>>
>>>Everybody "knew" longs were 32 bits, shorts and ints were both 16 bits,
>>>chars were 8 bits and we coded under that assumption. Lots and lots of
>>>code broke when we moved from 16 bit to 32 bit machines and the size of
>>>an int changed as a result.
>>>
>>
>> And, unfortunately, the types often were not abstracted behind
>> a typedef. The process identifer, group identifier and user
>> identifers were all 16-bit as well. This made for a painful
>> conversion to 32-bit PID/GID/UID in SVR4 (accompanied by abstract
>> types pid_t, gid_t, uid_t which, when used correctly, mean that
>> applications only needed a simple recompile to handle a change in width).
>
> There were no typedefs back then (at least I don't remember them that
> far back, and they don't appear in either Ritchie's reference manual nor
> Kernighan's tutorial).
FWIW, my copy of K&R (Copyright 1978) has a whole section (Chapter 6.9) on typedefs
The "C Programming Language - Reference Manual" (by Dennis M. Richie) published as
Appendix A of that edition of K&R also includes a section (8.8 Typedef) on typedef,
along with the BNF for it in section 18.2 ("Declarations").
--
Lew Pitcher
"In Skills, We Trust"
[toc] | [prev] | [next] | [standalone]
| From | Keith Thompson <Keith.S.Thompson+u@gmail.com> |
|---|---|
| Date | 2021-04-27 13:33 -0700 |
| Message-ID | <87wnsna2nv.fsf@nosuchdomain.example.com> |
| In reply to | #160411 |
Lew Pitcher <lew.pitcher@digitalfreehold.ca> writes:
> On Tue, 27 Apr 2021 10:55:37 -0600, Joe Pfeiffer wrote:
>> scott@slp53.sl.home (Scott Lurndal) writes:
>>> Joe Pfeiffer <pfeiffer@cs.nmsu.edu> writes:
>>>>Juha Nieminen <nospam@thanks.invalid> writes:
>>>>> However, the undetermined size of basic types (especially before
>>>>> standardization) makes it more likely for C programs, especially ones
>>>>> written back then, to be non-portable. Sure, even back when K&R first
>>>>> "soft-standardized" the C language you shouldn't have assumed a certain
>>>>> size for any basic type.
>>>>
>>>>Everybody "knew" longs were 32 bits, shorts and ints were both 16 bits,
>>>>chars were 8 bits and we coded under that assumption. Lots and lots of
>>>>code broke when we moved from 16 bit to 32 bit machines and the size of
>>>>an int changed as a result.
>>>>
>>>
>>> And, unfortunately, the types often were not abstracted behind
>>> a typedef. The process identifer, group identifier and user
>>> identifers were all 16-bit as well. This made for a painful
>>> conversion to 32-bit PID/GID/UID in SVR4 (accompanied by abstract
>>> types pid_t, gid_t, uid_t which, when used correctly, mean that
>>> applications only needed a simple recompile to handle a change in width).
>>
>> There were no typedefs back then (at least I don't remember them that
>> far back, and they don't appear in either Ritchie's reference manual nor
>> Kernighan's tutorial).
>
> FWIW, my copy of K&R (Copyright 1978) has a whole section (Chapter 6.9) on typedefs
> The "C Programming Language - Reference Manual" (by Dennis M. Richie) published as
> Appendix A of that edition of K&R also includes a section (8.8 Typedef) on typedef,
> along with the BNF for it in section 18.2 ("Declarations").
https://www.bell-labs.com/usr/dmr/www/cman.pdf (1975) doesn't mention typedef.
K&R1 (1978) does. That's as far as I've been able to narrow it down.
--
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
Working, but not speaking, for Philips Healthcare
void Void(void) { Void(); } /* The recursive call of the void */
[toc] | [prev] | [next] | [standalone]
| From | scott@slp53.sl.home (Scott Lurndal) |
|---|---|
| Date | 2021-04-27 19:27 +0000 |
| Message-ID | <jAZhI.77586$Y87.17799@fx08.iad> |
| In reply to | #160408 |
Joe Pfeiffer <pfeiffer@cs.nmsu.edu> writes: >scott@slp53.sl.home (Scott Lurndal) writes: > >> Joe Pfeiffer <pfeiffer@cs.nmsu.edu> writes: >>>Juha Nieminen <nospam@thanks.invalid> writes: >>> >>>> However, the undetermined size of basic types (especially before >>>> standardization) makes it more likely for C programs, especially ones >>>> written back then, to be non-portable. Sure, even back when K&R first >>>> "soft-standardized" the C language you shouldn't have assumed a certain >>>> size for any basic type. >>> >>>Everybody "knew" longs were 32 bits, shorts and ints were both 16 bits, >>>chars were 8 bits and we coded under that assumption. Lots and lots of >>>code broke when we moved from 16 bit to 32 bit machines and the size of >>>an int changed as a result. >>> >> >> And, unfortunately, the types often were not abstracted behind >> a typedef. The process identifer, group identifier and user >> identifers were all 16-bit as well. This made for a painful >> conversion to 32-bit PID/GID/UID in SVR4 (accompanied by abstract >> types pid_t, gid_t, uid_t which, when used correctly, mean that >> applications only needed a simple recompile to handle a change in width). > >There were no typedefs back then (at least I don't remember them that >far back, and they don't appear in either Ritchie's reference manual nor >Kernighan's tutorial). At the time of the SVR4 conversion in 1989, typedef was part of the language, and pid_t, gid_t, and uid_t were used subsequently for those purposes respectively. In addition, all API's were modified to use those abstract types both in SVR4 and via the SVID into POSIX.
[toc] | [prev] | [next] | [standalone]
| From | Kaz Kylheku <563-365-8930@kylheku.com> |
|---|---|
| Date | 2021-04-27 17:11 +0000 |
| Message-ID | <20210427101045.155@kylheku.com> |
| In reply to | #160407 |
On 2021-04-27, Scott Lurndal <scott@slp53.sl.home> wrote: > Joe Pfeiffer <pfeiffer@cs.nmsu.edu> writes: >>Juha Nieminen <nospam@thanks.invalid> writes: >> >>> However, the undetermined size of basic types (especially before >>> standardization) makes it more likely for C programs, especially ones >>> written back then, to be non-portable. Sure, even back when K&R first >>> "soft-standardized" the C language you shouldn't have assumed a certain >>> size for any basic type. >> >>Everybody "knew" longs were 32 bits, shorts and ints were both 16 bits, >>chars were 8 bits and we coded under that assumption. Lots and lots of >>code broke when we moved from 16 bit to 32 bit machines and the size of >>an int changed as a result. >> > > And, unfortunately, the types often were not abstracted behind > a typedef. Equally unfortunately, types were often abstracted behind bad typedefs. :) -- TXR Programming Language: http://nongnu.org/txr Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
[toc] | [prev] | [next] | [standalone]
| From | scott@slp53.sl.home (Scott Lurndal) |
|---|---|
| Date | 2021-04-27 14:28 +0000 |
| Message-ID | <CcVhI.13133$od.6566@fx15.iad> |
| In reply to | #160383 |
Eli the Bearded <*@eli.users.panix.com> writes:
>In comp.lang.c, Ben Bacarisse <ben.usenet@bsb.me.uk> wrote:
>> There was no C code 50 years ago. This is a bit of a quibble since
>> there was C code we'd just about recognise in about 1973 or 4, but some
>> of it would fool even gcc today. The biggest change was the great =<op>
>> to <op>= switch. This silently changed the meaning of a lot of code.
>
>Maybe five years ago I tried to compile some C code I found in buried
>in a tar file on a dusty ftp server[*]. The READ_ME implied it was last
>touched in June of 1980, the filename agreed with the year.
>
>Things I found tricky about the code:
>
>1. It predated printf being called that. I think it was just using
> print(). And that used "-lS" in the Makefile.
printf was printf from day one. Sounds like 'print' was provided
by an implementation library that wasn't included with the tar file you resurrected.
>
>2. Prototypes? Who needs em? ("#include <stdio.h>"? What, why?)
Prototypes were not used at the time, argument types were
'flexible', the programmer was expected to do the right thing.
>
>3. No need to declare ints, eg:
> main(argc, argv)
> char **argv;
> {
>
>4. Structs are implicitly unions:
> struct plot {
> char p_x;
> char p_y;
> } p_plot[LIM_PLOTS];
Now this isn't a union. p_x and p_y occupy unique memory
locations.
But member names (MoS - Member of Structure) were top-level
symbol table names, so any member from any struct could be
used with any other struct, so:
a
>
> /* ... */
>
> struct {
> int p_xy; /* used to set/transfer entire plot */
> };
p_xy has offset zero from the start of the structure; when software
uses p_xy (e.g. structpointer->p_xy) it has offset zero which allows
16-bit accesses to the two 8-bit fields in the p_plot struct.
>
>5. Implicit in above: seems like there is the expectation that
> sizeof(int) == 2.
Yes, for that particular application, it was assumed that
sizeof(int) == 2 * sizeof(char). Which was the case on the
PDP-11.
[toc] | [prev] | [next] | [standalone]
| From | Juha Nieminen <nospam@thanks.invalid> |
|---|---|
| Date | 2021-04-27 15:11 +0000 |
| Message-ID | <s699j2$jaq$1@gioia.aioe.org> |
| In reply to | #160402 |
In comp.lang.c++ Scott Lurndal <scott@slp53.sl.home> wrote:
>>2. Prototypes? Who needs em? ("#include <stdio.h>"? What, why?)
>
> Prototypes were not used at the time, argument types were
> 'flexible', the programmer was expected to do the right thing.
I love the example given in the original 1978 The C Programming
Language, which demonstrates how non-int-returning standard
library functions ought to be used:
FILE *fopen(), *in;
in = fopen("name", "r");
Apparently back in those days <stdio.h> couldn't be expected
to declare the fopen function.
[toc] | [prev] | [next] | [standalone]
| From | Ben Bacarisse <ben.usenet@bsb.me.uk> |
|---|---|
| Date | 2021-04-26 21:37 +0100 |
| Message-ID | <87czughjez.fsf@bsb.me.uk> |
| In reply to | #160342 |
jacobnavia <jacob@jacob.remcomp.fr> writes: > Since you spoke of a simple editor project in C, I showed you one > written 50 years ago of just 1700 lines. It compiles and runs 50 years > later. Please show me a complex program in C++ from 2000 that compiles > unmodified and runs today. The posted code can't be 50 years old. ed is 50 years old, but the original was not written in C (there was no C in 1971). The version posted uses void and function prototypes so it dates from the time C was first being standardised. A comment says it has been slightly modified. It would be nice to know if that was necessary to get it to compile, and if so, what the modification was. -- Ben.
[toc] | [prev] | [next] | [standalone]
| From | jacobnavia <jacob@jacob.remcomp.fr> |
|---|---|
| Date | 2021-04-26 22:48 +0200 |
| Message-ID | <s678uc$dbt$1@dont-email.me> |
| In reply to | #160369 |
Le 26/04/2021 à 22:37, Ben Bacarisse a écrit : > jacobnavia <jacob@jacob.remcomp.fr> writes: > >> Since you spoke of a simple editor project in C, I showed you one >> written 50 years ago of just 1700 lines. It compiles and runs 50 years >> later. Please show me a complex program in C++ from 2000 that compiles >> unmodified and runs today. > > The posted code can't be 50 years old. ed is 50 years old, but the > original was not written in C (there was no C in 1971). > OK, granted > The version posted uses void and function prototypes so it dates from > the time C was first being standardised. A comment says it has been > slightly modified. It would be nice to know if that was necessary to > get it to compile, and if so, what the modification was. > I modifiedit to get rid of warnings of gcc, by changing char * into unsigned char *. Not a big deal. You can download the original from the URL I included
[toc] | [prev] | [next] | [standalone]
| From | scott@slp53.sl.home (Scott Lurndal) |
|---|---|
| Date | 2021-04-26 21:53 +0000 |
| Message-ID | <gDGhI.32856$D16.32548@fx40.iad> |
| In reply to | #160369 |
Ben Bacarisse <ben.usenet@bsb.me.uk> writes: >jacobnavia <jacob@jacob.remcomp.fr> writes: > >> Since you spoke of a simple editor project in C, I showed you one >> written 50 years ago of just 1700 lines. It compiles and runs 50 years >> later. Please show me a complex program in C++ from 2000 that compiles >> unmodified and runs today. > >The posted code can't be 50 years old. ed is 50 years old, but the >original was not written in C (there was no C in 1971). ed first appeared in V2. ed2.s and ed3.s https://minnie.tuhs.org/cgi-bin/utree.pl?file=V2/cmd/ed2.s ed.c first appeared in V6 (1975). https://minnie.tuhs.org/cgi-bin/utree.pl?file=V6/usr/source/s1/ed.c
[toc] | [prev] | [next] | [standalone]
| From | Ben Bacarisse <ben.usenet@bsb.me.uk> |
|---|---|
| Date | 2021-04-27 01:34 +0100 |
| Message-ID | <87mttkftua.fsf@bsb.me.uk> |
| In reply to | #160380 |
scott@slp53.sl.home (Scott Lurndal) writes: > Ben Bacarisse <ben.usenet@bsb.me.uk> writes: >>jacobnavia <jacob@jacob.remcomp.fr> writes: >> >>> Since you spoke of a simple editor project in C, I showed you one >>> written 50 years ago of just 1700 lines. It compiles and runs 50 years >>> later. Please show me a complex program in C++ from 2000 that compiles >>> unmodified and runs today. >> >>The posted code can't be 50 years old. ed is 50 years old, but the >>original was not written in C (there was no C in 1971). > > ed first appeared in V2. ed2.s and ed3.s Oh. I found a man page dated 1971 in V1 Unix. > https://minnie.tuhs.org/cgi-bin/utree.pl?file=V2/cmd/ed2.s > > ed.c first appeared in V6 (1975). Yup. ed.c can't predate C! > https://minnie.tuhs.org/cgi-bin/utree.pl?file=V6/usr/source/s1/ed.c -- Ben.
[toc] | [prev] | [next] | [standalone]
| From | Guillaume <message@bottle.org> |
|---|---|
| Date | 2021-04-26 18:48 +0200 |
| Message-ID | <s66qtf$506$1@gioia.aioe.org> |
| In reply to | #160340 |
Le 26/04/2021 à 07:22, Juha Nieminen a écrit : > In comp.lang.c++ jacobnavia <jacob@jacob.remcomp.fr> wrote: >> The malloc allocates the working area of the editor. It is not freed >> because it will be always needed; it is realloc'ed when needed, and >> freed by the OS when the program terminates. This is abvious for anyone >> reading C. > > The main point is that malloc()'ing something and not free()'ing it is > bad practice. Not only does it teach you bad habits, it teaches other > people reading the code this same bad habit. Whereas I personally agree with this, I reckon there are different ways of seeing it, some in favor of actually doing exactly what they did. If you assume that all malloc'ed memory will be reclaimed when the program terminates, then not explicitely freeing it in this case (where you would be free it just before the program terminates anyway) actually makes sense and shows you know what you're doing. One can even argue that useless statements are just code pollution. Now regarding the above assumption, whereas it's reasonable on any "decent" OS, including the one(s) the authors were targetting at the time they wrote this piece of code, I could not find any explicit mention of this in the C standard regarding memory allocation - unless of course I missed it, which means the hosted environment is not required to reclaim allocated memory upon program termination. It's implementation-defined, thus the quoted program is, by definition, non-portable. Which is one good reason to claim it's bad practice indeed. As to another reason why I would not do this: code reusability. I tend to write code so that it can be reused. The way it's implemented in the quoted program, it's just not reusable if you wanted to make a "text editor" component out of it and reuse it in a completely different program.
[toc] | [prev] | [next] | [standalone]
| From | James Kuyper <jameskuyper@alumni.caltech.edu> |
|---|---|
| Date | 2021-04-26 13:54 -0400 |
| Message-ID | <s66uor$bg2$1@dont-email.me> |
| In reply to | #160340 |
On 4/26/21 1:22 AM, Juha Nieminen wrote: ... > The main point is that malloc()'ing something and not free()'ing it is > bad practice. Not only does it teach you bad habits, it teaches other > people reading the code this same bad habit. This is especially > egregious in code that's being used for didactic purposes out there, > for thousands and thousands of students to see. There's a fundamental problem with arguments of that type: if the person you're arguing with doesn't already accept that it is a bad practice, he's not going to have any problems with teaching others to adopt it. If he does accept that it's a bad practice, he'll stop using it for that reason alone, and will then automatically become a good example for others to follow. So bringing up the effects on other people doesn't actually do anything useful for your argument.
[toc] | [prev] | [next] | [standalone]
| From | Jorgen Grahn <grahn+nntp@snipabacken.se> |
|---|---|
| Date | 2021-04-23 20:00 +0000 |
| Message-ID | <slrns869qd.2ptb.grahn+nntp@frailea.sa.invalid> |
| In reply to | #160282 |
["Followup-To:" header set to comp.lang.c.] On Fri, 2021-04-23, Juha Nieminen wrote: > In comp.lang.c++ jacobnavia <jacob@jacob.remcomp.fr> wrote: >> Attached is the source code for the 10th edition of Unix of the "ed" >> text editor, published by Brian Kernighan for his CS classes at >> Princeton in 2001. > > Maybe it has significant historic value, but as a C program I don't think > it's that great. > > It's quite hard to decipher (especially since it follows the typical > 70's and 80's C style of using very short cryptic names everywhere), IMO, longer names without any other improvements, aren't an improvement. The global 'int pflag' here, for example, would suck no matter how you rename it. If it's changed to an enum, and wrapped and documented in a struct EditorState[1], it doesn't need to be renamed. (But I have a maths background, and like short names.) /Jorgen [1] I may misremember the code -- I only took a brief look. -- // Jorgen Grahn <grahn@ Oo o. . . \X/ snipabacken.se> O o .
[toc] | [prev] | [next] | [standalone]
| From | scott@slp53.sl.home (Scott Lurndal) |
|---|---|
| Date | 2021-04-23 20:25 +0000 |
| Message-ID | <W2GgI.15917$zx1.6739@fx20.iad> |
| In reply to | #160294 |
Jorgen Grahn <grahn+nntp@snipabacken.se> writes: >["Followup-To:" header set to comp.lang.c.] > >On Fri, 2021-04-23, Juha Nieminen wrote: >> In comp.lang.c++ jacobnavia <jacob@jacob.remcomp.fr> wrote: >>> Attached is the source code for the 10th edition of Unix of the "ed" >>> text editor, published by Brian Kernighan for his CS classes at >>> Princeton in 2001. >> >> Maybe it has significant historic value, but as a C program I don't think >> it's that great. >> >> It's quite hard to decipher (especially since it follows the typical >> 70's and 80's C style of using very short cryptic names everywhere), > >IMO, longer names without any other improvements, aren't an >improvement. The global 'int pflag' here, for example, would suck no >matter how you rename it. If it's changed to an enum, and wrapped and >documented in a struct EditorState[1], it doesn't need to be renamed. And when ed(1) was written, names could be no longer than 8 bytes. I just looked at the Unixware2 version (circa 1993) - it is basically the same, but is closer to 3000 lines, due to additions for handling I18N, editing 'crypt'ed files, Security and Locale support. Still uses sbrk() for dynamic memory allocation.
[toc] | [prev] | [next] | [standalone]
| From | Juha Nieminen <nospam@thanks.invalid> |
|---|---|
| Date | 2021-04-26 05:29 +0000 |
| Message-ID | <s65j3m$9dc$1@gioia.aioe.org> |
| In reply to | #160294 |
In comp.lang.c++ Jorgen Grahn <grahn+nntp@snipabacken.se> wrote:
> ["Followup-To:" header set to comp.lang.c.]
>
> On Fri, 2021-04-23, Juha Nieminen wrote:
>> In comp.lang.c++ jacobnavia <jacob@jacob.remcomp.fr> wrote:
>>> Attached is the source code for the 10th edition of Unix of the "ed"
>>> text editor, published by Brian Kernighan for his CS classes at
>>> Princeton in 2001.
>>
>> Maybe it has significant historic value, but as a C program I don't think
>> it's that great.
>>
>> It's quite hard to decipher (especially since it follows the typical
>> 70's and 80's C style of using very short cryptic names everywhere),
>
> IMO, longer names without any other improvements, aren't an
> improvement. The global 'int pflag' here, for example, would suck no
> matter how you rename it. If it's changed to an enum, and wrapped and
> documented in a struct EditorState[1], it doesn't need to be renamed.
I don't agree. Code becomes more readable when cryptic and non-descript
names are changed to names that make the code more self-documenting,
even without any other changes.
As an example, suppose you see a line of code like this:
convert(a, b);
Well, that doesn't say much. We have absolutely no way of knowing what
it does. But suppose the function were renamed to:
convert_string_to_wstring(a, b);
Ah, now we are talking. Now it actually says what it's doing.
There's of course still the minor problem that we don't know which
parameter is the string, and which one is the wstring. But we can also
rename the variables:
convert_string_to_wstring(dest, src);
And suddenly, a line of code that told us absolutely nothing, now
tells us everything.
(The above example is actually based on actual production code I have seen.)
[toc] | [prev] | [next] | [standalone]
| From | om@iki.fi (Otto J. Makela) |
|---|---|
| Date | 2021-04-23 19:25 +0300 |
| Message-ID | <87tunx3r3p.fsf@tigger.extechop.net> |
| In reply to | #160277 |
jacobnavia <jacob@jacob.remcomp.fr> wrote: > Attached is the source code for the 10th edition of Unix of the "ed" > text editor, published by Brian Kernighan for his CS classes at > Princeton in 2001. I like that it indeed does compile, but the fact that there are hardly any comments, nor do the variable names really explain what is going on hardly makes this a shining example of recommendable coding practices. -- /* * * Otto J. Makela <om@iki.fi> * * * * * * * * * */ /* Phone: +358 40 765 5772, ICBM: N 60 10' E 24 55' */ /* Mail: Mechelininkatu 26 B 27, FI-00100 Helsinki */ /* * * Computers Rule 01001111 01001011 * * * * * * */
[toc] | [prev] | [next] | [standalone]
| From | Bonita Montero <Bonita.Montero@gmail.com> |
|---|---|
| Date | 2021-04-26 18:04 +0200 |
| Message-ID | <s66o9k$a0e$1@dont-email.me> |
| In reply to | #160277 |
Use C++ - much less code, more maintainable and more readable code if you use it properly. Sth. like malloc() f.e. is really disgusting when compared to using a vector<>.
[toc] | [prev] | [standalone]
Page 4 of 4 — ← Prev page 1 2 3 [4]
Back to top | Article view | comp.lang.c
csiph-web