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 | 20 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 3 of 4 — ← Prev page 1 2 [3] 4 Next page →
| From | Juha Nieminen <nospam@thanks.invalid> |
|---|---|
| Date | 2021-04-26 09:57 +0000 |
| Message-ID | <s662qr$1f6i$1@gioia.aioe.org> |
| In reply to | #160342 |
In comp.lang.c++ jacobnavia <jacob@jacob.remcomp.fr> wrote: > Since you spoke of a simple editor project in C, I showed you one > written 50 years ago of just 1700 lines. Not comparable because my entire point was about how laborious and error-prone it is to handle *dynamically allocated* (and length-changing) strings. The program you posted uses a static array for the lines, with a fixed maximum length. Not really comparable. > It compiles and runs 50 years > later. Please show me a complex program in C++ from 2000 that compiles > unmodified and runs today. Can you show me a C++ program from 2000 that doesn't? > 2) In many applications, the information gathered and stored using > malloc will be used until the exit of the program: in a compiler, for > instance, or in a text editor. A good strategy is to malloc and never > free, since all the memory is used until the program exits. This > simplifies and accelerates the program. For starters, allocating some kind of memory buffer that gets reused in the program for many things doesn't stop you from freeing it at the end. Secondly, that's not really an option for a text editor where you have to load a text file into RAM and allow the user to edit its lines (by eg. adding content to them). You can't do this with one single allocation. (You can read the file into RAM with one single allocation, but you can't then support adding stuff to it without reallocation. Moreover, if it's a text editor you probably want to allocate each line individually to allow them to be grown efficiently, without having to realloc the entire thing.) >> In loops where the >> amount of leaked memory will start increasing and increasing indefinitely. >> When the code is complicated enough, and there are hundreds and hundreds >> of such non-freed mallocs all over the place, in complex code, it becomes >> a nightmare to fix. >> > > This has a simple fix (that I have used a lot): > 1) Replace all malloc calls by calls to Mymalloc > 2) Write a simple function Mymalloc that allocates from a heap > 3) Free the heap when the program terminates. This way, a program that > never freed anything can be included into a larger project that needs > the free(). That doesn't make any difference. If you are leaking memory in a loop, your program will start consuming more and more RAM until it runs out of it. It makes no difference whether you use your own allocator for this or not, if you never free the memory blocks that you don't need anymore. >> It makes it sound like every time you call malloc(), it will make an OS >> call, which will make the OS allocate a block of memory of that size >> (which wasn't allocated for the program before), > > This is exactly what happens. The OS allocates a block of memory that > malloc/free manages. All mallocs use some API for calling the OS. No, it's not. malloc() and free() are (typically) handled by the C runtime library. This library will make a system call to ask for more heap space only if needed. If a malloc() can be done within the current heap, it won't ask the OS for more. The only thing that the OS sees is the heap expansion requests (and possibly heap shrinking requests). It doesn't see the individual mallocs and frees. It doesn't know nor care which parts of the heap are "unused" and which are "in use" by the program internally. > and that the OS itself >> keeps track of these possibly thousands and thousands, sometimes millions >> of tiny allocations (think of a linked list, or a binary tree, where each >> node is allocated individually), and once the program terminates, the OS >> will "garbage-collect" all these tiny individual allocations and free >> them again for other programs to use. In other words, as if the OS called >> free() for you, for each malloc() you did (and didn't explicitly free), >> when the program ends. > > The OS frees the heap of the application (conceptually). That's what I said. It doesn't care about any "mallocs" or "frees" of the program. It just sees a heap, and doesn't care what the program does with it. When the program ends, the OS reclaims that heap.
[toc] | [prev] | [next] | [standalone]
| From | Robert Latest <boblatest@yahoo.com> |
|---|---|
| Date | 2021-04-26 10:41 +0000 |
| Message-ID | <ienjmeFl5j5U2@mid.individual.net> |
| In reply to | #160350 |
["Followup-To:" header set to comp.lang.c.] Juha Nieminen wrote: > Not comparable because my entire point was about how laborious and > error-prone it is to handle *dynamically allocated* (and length-changing) > strings. All coding is laborious and error prone if you're both lazy and sloppy. -- robert
[toc] | [prev] | [next] | [standalone]
| From | jacobnavia <jacob@jacob.remcomp.fr> |
|---|---|
| Date | 2021-04-26 13:20 +0200 |
| Message-ID | <s667mf$5uc$1@dont-email.me> |
| In reply to | #160350 |
Le 26/04/2021 à 11:57, Juha Nieminen a écrit :
> Can you show me a C++ program from 2000 that doesn't?
Breaking changes in C++ 2011
1) the introduction of explicit operator bool() in the standard library,
replacing old instances of operator void*().
2) #define u8 "abc"
const char *s = u8"def"; // Previously "abcdef", now "def"
3) #define _x "there"
"hello"_x // now a user-defined-string-literal. Previously, expanded _x
4) New keywords: alignas, alignof, char16_t, char32_t, constexpr,
decltype, noexcept, nullptr, static_assert, and thread_local
5) Certain integer literals larger than can be represented by long could
change from an unsigned integer type to signed long long.
6) Valid C++ 2003 code that uses integer division rounds the result
toward 0 or toward negative infinity, whereas C++0x always rounds the
result toward 0.
7) struct A { private: A(); };
struct B : A { };
int main() { sizeof B(); /* valid in C++03, invalid in C++0x */ }
Such sizeof tricks have been used by some SFINAE, and needs to be
changed now :)
8) banning of narrowing conversions during aggregate initialization:
int a = {1.0; }; // error
9) Implicit move breaks C++ 2003 code. The long explanation why is to be
found at:
http://web.archive.org/web/20140110035813/http://cpp-next.com/archive/2010/10/implicit-move-must-go/
10) I remember that in an older version of C++ the templates arguments
are checked and must be defined at the point of expansion, the new
version of the language needs that they are defined at the point of
definition. Or something like that. I earned two weeks consulting to
update a huge codebase. Actually I love C++ :-)
And I will stop here... You apparently have no idea how c++ has changed
over the years, with each new version incompatible in some point with
the older one.
Only in C you can still use the code of 50 years ago.
[toc] | [prev] | [next] | [standalone]
| From | Juha Nieminen <nospam@thanks.invalid> |
|---|---|
| Date | 2021-04-26 13:17 +0000 |
| Message-ID | <s66ehe$1mju$1@gioia.aioe.org> |
| In reply to | #160354 |
In comp.lang.c++ jacobnavia <jacob@jacob.remcomp.fr> wrote:
> Le 26/04/2021 à 11:57, Juha Nieminen a écrit :
>> Can you show me a C++ program from 2000 that doesn't?
>
> Breaking changes in C++ 2011
I think all the major C++ compilers support C++98 mode.
And it's not like C hasn't change either. This compiles as C89 but not
as C99:
#include <stdio.h>
int main()
{
int restrict = 1, inline = 2;
printf("%i %i\n", restrict, inline);
return 0;
}
[toc] | [prev] | [next] | [standalone]
| From | jacobnavia <jacob@jacob.remcomp.fr> |
|---|---|
| Date | 2021-04-26 19:53 +0200 |
| Message-ID | <s66und$8v7$1@dont-email.me> |
| In reply to | #160356 |
Le 26/04/2021 à 15:17, Juha Nieminen a écrit :
> In comp.lang.c++ jacobnavia <jacob@jacob.remcomp.fr> wrote:
>> Le 26/04/2021 à 11:57, Juha Nieminen a écrit :
>>> Can you show me a C++ program from 2000 that doesn't?
>>
>> Breaking changes in C++ 2011
>
> I think all the major C++ compilers support C++98 mode.
>
> And it's not like C hasn't change either. This compiles as C89 but not
> as C99:
>
> #include <stdio.h>
>
> int main()
> {
> int restrict = 1, inline = 2;
> printf("%i %i\n", restrict, inline);
> return 0;
> }
>
Yes, that is why I did NOT even mention the same problems that C++ has
(auto keyword, and MANY others, much more than C)
[toc] | [prev] | [next] | [standalone]
| From | David Brown <david.brown@hesbynett.no> |
|---|---|
| Date | 2021-04-26 20:34 +0200 |
| Message-ID | <s67136$p59$1@dont-email.me> |
| In reply to | #160363 |
On 26/04/2021 19:53, jacobnavia wrote:
> Le 26/04/2021 à 15:17, Juha Nieminen a écrit :
>> In comp.lang.c++ jacobnavia <jacob@jacob.remcomp.fr> wrote:
>>> Le 26/04/2021 à 11:57, Juha Nieminen a écrit :
>>>> Can you show me a C++ program from 2000 that doesn't?
>>>
>>> Breaking changes in C++ 2011
>>
>> I think all the major C++ compilers support C++98 mode.
>>
>> And it's not like C hasn't change either. This compiles as C89 but not
>> as C99:
>>
>> #include <stdio.h>
>>
>> int main()
>> {
>> int restrict = 1, inline = 2;
>> printf("%i %i\n", restrict, inline);
>> return 0;
>> }
>>
>
> Yes, that is why I did NOT even mention the same problems that C++ has
> (auto keyword, and MANY others, much more than C)
Yes, you did - your number 4 item was a list of new keywords whose only
backwards compatibility issue is if they happen to be used as
identifiers. (There are more than in C99 - no arguments there. I'd not
expect significantly more conflicts, however.)
There are a few cases where it might be reasonable to think /real/ code
written for C++03 would no longer be valid (or have the same effect)
when compiled as C++11 or newer. But they would be rare. Listing silly
things like defining "u8" as a macro of a string and using it for string
concatenation (without a space) is just petty. It is not a realistic
concern, nor an example of what Juha asked for - it is just FUD, and a
sign of desperation. You prefer C to C++ - that's fine, everyone has
their preferences. But if you don't have real reasons, there's no need
to invent unrealistic reasons.
[toc] | [prev] | [next] | [standalone]
| From | jacobnavia <jacob@jacob.remcomp.fr> |
|---|---|
| Date | 2021-04-26 22:49 +0200 |
| Message-ID | <s67903$dbt$2@dont-email.me> |
| In reply to | #160365 |
Le 26/04/2021 à 20:34, David Brown a écrit :
> On 26/04/2021 19:53, jacobnavia wrote:
>> Le 26/04/2021 à 15:17, Juha Nieminen a écrit :
>>> In comp.lang.c++ jacobnavia <jacob@jacob.remcomp.fr> wrote:
>>>> Le 26/04/2021 à 11:57, Juha Nieminen a écrit :
>>>>> Can you show me a C++ program from 2000 that doesn't?
>>>>
>>>> Breaking changes in C++ 2011
>>>
>>> I think all the major C++ compilers support C++98 mode.
>>>
>>> And it's not like C hasn't change either. This compiles as C89 but not
>>> as C99:
>>>
>>> #include <stdio.h>
>>>
>>> int main()
>>> {
>>> int restrict = 1, inline = 2;
>>> printf("%i %i\n", restrict, inline);
>>> return 0;
>>> }
>>>
>>
>> Yes, that is why I did NOT even mention the same problems that C++ has
>> (auto keyword, and MANY others, much more than C)
>
> Yes, you did - your number 4 item was a list of new keywords whose only
> backwards compatibility issue is if they happen to be used as
> identifiers. (There are more than in C99 - no arguments there. I'd not
> expect significantly more conflicts, however.)
>
> There are a few cases where it might be reasonable to think /real/ code
> written for C++03 would no longer be valid (or have the same effect)
> when compiled as C++11 or newer. But they would be rare. Listing silly
> things like defining "u8" as a macro of a string and using it for string
> concatenation (without a space) is just petty. It is not a realistic
> concern, nor an example of what Juha asked for - it is just FUD, and a
> sign of desperation. You prefer C to C++ - that's fine, everyone has
> their preferences. But if you don't have real reasons, there's no need
> to invent unrealistic reasons.
>
>
Sure sure, I am desperate. But you ignored the problem with templates...
and many others I mentioned
[toc] | [prev] | [next] | [standalone]
| From | David Brown <david.brown@hesbynett.no> |
|---|---|
| Date | 2021-04-27 10:59 +0200 |
| Message-ID | <s68jpn$3ci$1@dont-email.me> |
| In reply to | #160372 |
On 26/04/2021 22:49, jacobnavia wrote:
> Le 26/04/2021 à 20:34, David Brown a écrit :
>> On 26/04/2021 19:53, jacobnavia wrote:
>>> Le 26/04/2021 à 15:17, Juha Nieminen a écrit :
>>>> In comp.lang.c++ jacobnavia <jacob@jacob.remcomp.fr> wrote:
>>>>> Le 26/04/2021 à 11:57, Juha Nieminen a écrit :
>>>>>> Can you show me a C++ program from 2000 that doesn't?
>>>>>
>>>>> Breaking changes in C++ 2011
>>>>
>>>> I think all the major C++ compilers support C++98 mode.
>>>>
>>>> And it's not like C hasn't change either. This compiles as C89 but not
>>>> as C99:
>>>>
>>>> #include <stdio.h>
>>>>
>>>> int main()
>>>> {
>>>> int restrict = 1, inline = 2;
>>>> printf("%i %i\n", restrict, inline);
>>>> return 0;
>>>> }
>>>>
>>>
>>> Yes, that is why I did NOT even mention the same problems that C++ has
>>> (auto keyword, and MANY others, much more than C)
>>
>> Yes, you did - your number 4 item was a list of new keywords whose only
>> backwards compatibility issue is if they happen to be used as
>> identifiers. (There are more than in C99 - no arguments there. I'd not
>> expect significantly more conflicts, however.)
>>
>> There are a few cases where it might be reasonable to think /real/ code
>> written for C++03 would no longer be valid (or have the same effect)
>> when compiled as C++11 or newer. But they would be rare. Listing silly
>> things like defining "u8" as a macro of a string and using it for string
>> concatenation (without a space) is just petty. It is not a realistic
>> concern, nor an example of what Juha asked for - it is just FUD, and a
>> sign of desperation. You prefer C to C++ - that's fine, everyone has
>> their preferences. But if you don't have real reasons, there's no need
>> to invent unrealistic reasons.
>>
>>
>
> Sure sure, I am desperate. But you ignored the problem with templates...
> and many others I mentioned
I didn't ignore them, I just didn't mention them. There /are/ backwards
incompatible changes between C++03 and C++11 (and later versions). Some
of these will be in language or library features that might well occur
in real code. It would be perfectly reasonable to point out these
differences - especially if you can give examples or references to real
cases.
What is /unreasonable/ and shows desperation (perhaps people moving to
C++ is bad for your business) is listing every little point you can
think of, regardless of realism. It makes a mockery of your /real/ points.
[toc] | [prev] | [next] | [standalone]
| From | Ben Bacarisse <ben.usenet@bsb.me.uk> |
|---|---|
| Date | 2021-04-26 22:04 +0100 |
| Message-ID | <877dkohi65.fsf@bsb.me.uk> |
| In reply to | #160354 |
jacobnavia <jacob@jacob.remcomp.fr> writes: > 2) #define u8 "abc" > const char *s = u8"def"; // Previously "abcdef", now "def" C has the same breaking change, but, just as with C++, you can usually ask the compiler to use an older standard. > Only in C you can still use the code of 50 years ago. 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. -- Ben.
[toc] | [prev] | [next] | [standalone]
| From | Eli the Bearded <*@eli.users.panix.com> |
|---|---|
| Date | 2021-04-26 22:19 +0000 |
| Message-ID | <eli$2104261749@qaz.wtf> |
| In reply to | #160376 |
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.
2. Prototypes? Who needs em? ("#include <stdio.h>"? What, why?)
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];
/* ... */
struct {
int p_xy; /* used to set/transfer entire plot */
};
5. Implicit in above: seems like there is the expectation that
sizeof(int) == 2.
Items 1 to 3 made things difficult. Items 4 and 5 meant actual code
audits were needed.
[*] I last saw it here, but that 404's today:
http://mirror.cc.vt.edu/pub2/Ancient_Unix/Applications/Shoppa_Tapes/usenix_80_delaware.tar.gz
Elijah
------
the .c files were easier to make sense of than the .o files included
[toc] | [prev] | [next] | [standalone]
| From | Keith Thompson <Keith.S.Thompson+u@gmail.com> |
|---|---|
| Date | 2021-04-26 16:07 -0700 |
| Message-ID | <87eeewbq65.fsf@nosuchdomain.example.com> |
| 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.
I believe printf is older than C. A form of it existed by that name in
B, and it's used (with an implementation presented) in the 1974 and 1975
editions of the C manual. But a particular program might have chosen to
use something else.
> 2. Prototypes? Who needs em? ("#include <stdio.h>"? What, why?)
Prototypes still aren't mandatory, though calling printf without a
visible declaration has been a constraint violation since 1999 (and
undefined behavior in C89/C90, but very likely to work).
> 3. No need to declare ints, eg:
> main(argc, argv)
> char **argv;
> {
Valid in C90. Add "int" to main and argc and it's still valid (but
obsolescent).
> 4. Structs are implicitly unions:
> struct plot {
> char p_x;
> char p_y;
> } p_plot[LIM_PLOTS];
>
> /* ... */
>
> struct {
> int p_xy; /* used to set/transfer entire plot */
> };
A struct member name implied a type and offset, and was not tied to
the struct type. That's why a lot of member names have unique prefixes,
like tm_sec and friends. I think C89/C90 changed that.
> 5. Implicit in above: seems like there is the expectation that
> sizeof(int) == 2.
There were implementations with sizeof(int)!=2 as early as the late
1980s, but there's never been any shortage of non-portable code.
> Items 1 to 3 made things difficult. Items 4 and 5 meant actual code
> audits were needed.
>
> [*] I last saw it here, but that 404's today:
> http://mirror.cc.vt.edu/pub2/Ancient_Unix/Applications/Shoppa_Tapes/usenix_80_delaware.tar.gz
>
> Elijah
> ------
> the .c files were easier to make sense of than the .o files included
--
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 | Joe Pfeiffer <pfeiffer@cs.nmsu.edu> |
|---|---|
| Date | 2021-04-26 17:08 -0600 |
| Message-ID | <1bpmygr6d2.fsf@pfeifferfamily.net> |
| 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.
It was called printf() at least as long ago as Kernighan's "Programming
in C - A Tutorial", which dates from 1974. So the print() you came
across was some other function.
> 2. Prototypes? Who needs em? ("#include <stdio.h>"? What, why?)
>
> 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];
>
> /* ... */
>
> struct {
> int p_xy; /* used to set/transfer entire plot */
> };
*Lord* that one bit me hard early on. Having all struct members
use a single namespace is a decision I still don't understand (I don't
care how limited the machines running the compiler were).
> 5. Implicit in above: seems like there is the expectation that
> sizeof(int) == 2.
>
>
> Items 1 to 3 made things difficult. Items 4 and 5 meant actual code
> audits were needed.
>
> [*] I last saw it here, but that 404's today:
> http://mirror.cc.vt.edu/pub2/Ancient_Unix/Applications/Shoppa_Tapes/usenix_80_delaware.tar.gz
>
> Elijah
> ------
> the .c files were easier to make sense of than the .o files included
[toc] | [prev] | [next] | [standalone]
| From | Keith Thompson <Keith.S.Thompson+u@gmail.com> |
|---|---|
| Date | 2021-04-26 16:57 -0700 |
| Message-ID | <87a6pkbnuj.fsf@nosuchdomain.example.com> |
| In reply to | #160385 |
Joe Pfeiffer <pfeiffer@cs.nmsu.edu> writes:
> Eli the Bearded <*@eli.users.panix.com> writes:
[...]
>> 4. Structs are implicitly unions:
>> struct plot {
>> char p_x;
>> char p_y;
>> } p_plot[LIM_PLOTS];
>>
>> /* ... */
>>
>> struct {
>> int p_xy; /* used to set/transfer entire plot */
>> };
>
> *Lord* that one bit me hard early on. Having all struct members
> use a single namespace is a decision I still don't understand (I don't
> care how limited the machines running the compiler were).
As of the 1975 C manual, a "prefix.identifier" or "prefix->identifier"
expression *assumed* that the LHS was of the correct type. For "->",
it wasn't even required to be a pointer; it could be a pointer,
character, or integer.
K&R1 (1978) imposed the requirement for the LHS to be of the correct
struct or union type for "." or a pointer to the correct struct or union
type for "->".
If you ran into that problem, it must have been some very early code
and/or a very old compiler.
I've used a compiler (VAXC) that knew about the modern "+=" compound
assignment operators, but also accepted the older "=+" forms -- and
preferred them in ambiguous cases. That was in the late 1990s. That's
also a change that was made between 1975 and K&R1 in 1978. Fortunately,
though VAXC was available, we mostly used the more modern DECC.
[...]
--
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 | Joe Pfeiffer <pfeiffer@cs.nmsu.edu> |
|---|---|
| Date | 2021-04-26 21:42 -0600 |
| Message-ID | <1blf94qtoi.fsf@pfeifferfamily.net> |
| In reply to | #160386 |
Keith Thompson <Keith.S.Thompson+u@gmail.com> writes: > Joe Pfeiffer <pfeiffer@cs.nmsu.edu> writes: >> >> *Lord* that one bit me hard early on. Having all struct members >> use a single namespace is a decision I still don't understand (I don't >> care how limited the machines running the compiler were). > > As of the 1975 C manual, a "prefix.identifier" or "prefix->identifier" > expression *assumed* that the LHS was of the correct type. For "->", > it wasn't even required to be a pointer; it could be a pointer, > character, or integer. > > K&R1 (1978) imposed the requirement for the LHS to be of the correct > struct or union type for "." or a pointer to the correct struct or union > type for "->". > > If you ran into that problem, it must have been some very early code > and/or a very old compiler. It wasn't an old compiler... at the time... it was roughly 1977 or so.
[toc] | [prev] | [next] | [standalone]
| From | Kaz Kylheku <563-365-8930@kylheku.com> |
|---|---|
| Date | 2021-04-27 00:46 +0000 |
| Message-ID | <20210426173148.187@kylheku.com> |
| In reply to | #160383 |
On 2021-04-26, Eli the Bearded <*@eli.users.panix.com> wrote:
> 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.
>
> 2. Prototypes? Who needs em? ("#include <stdio.h>"? What, why?)
Version 7 Unix in 1979 had <stdio.h>, and fprintf and printf functions,
wrappers around an assembly language routine taking the stream as a
parameter. In version 5 (1974), printf was still a dedicated assembly
routine. It had the "f" in the name.
> 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];
>
> /* ... */
>
> struct {
> int p_xy; /* used to set/transfer entire plot */
> };
That was a feature of early C. Basically, no type checking. If you
wrote
ptr->member
then it would look up member in a global dictionary of *all* structure
members that have been declared in the translation unit, and not in the
*ptr type! And then it would just generate the machine code to access
the pointer relative to that offset.
This is part of the reason why Unix structure members have prefixes,
just like the convention you see in the code you found above.
E.g. "struct stat" has "st_mtime", "st_size" and so on.
That situation persists until today.
Another funny fact is that some early compilers used a static buffer for
returning structs instead of the stack. Oops, not safe w.r.t. signals or
threading.
> 5. Implicit in above: seems like there is the expectation that
> sizeof(int) == 2.
Newly written code today has assumptions like this. TOns of code written
for 16-bit systems (PC's with MS-DOS, for instance) was riddled with
sizeof(int) == 2 == 16 bits assumptions.
--
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
[toc] | [prev] | [next] | [standalone]
| From | Juha Nieminen <nospam@thanks.invalid> |
|---|---|
| Date | 2021-04-27 04:51 +0000 |
| Message-ID | <s68596$17de$1@gioia.aioe.org> |
| In reply to | #160383 |
In comp.lang.c++ Eli the Bearded <*@eli.users.panix.com> wrote: > 5. Implicit in above: seems like there is the expectation that > sizeof(int) == 2. That's actually a good point, which I didn't myself think of earlier. Several arguments have been made in this thread that C is very "portable", and that C code written in the 1970's still compiles and works just fine (well, at least if you tell gcc/clang to use the C89 standard, hopefully). 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. (I don't know if sizeof(char) was guaranteed to be 1 even since K&R, but even then, and to this day, you can't really trust that it's actually one 8-bit byte, only that the sizes of all other types are multiples of it.) There were no fancy uint32_t and other such type aliases back then (and not even in C89), so there wasn't really a sure way to have a basic type of a particular size. (You can check if a basic type is of a given size with #if, and try several of them to see if one of them is of the desired size, and produce an #error if none of them are, but that's as far as you could go. In fact, even today that's technically as far as you can go, even with the possibly existing standard typedefs.) For most code it's enough for basic types to have a minimum size, but this isn't always the case, and it's easy to write code that assumes a particular size for such a type and breaks if it actually isn't of that size. I suppose the conclusion is that maybe C code written in the 70's does compile and work today... but only if it was properly written. If it wasn't properly written, it's perfectly possible it won't work today, in a different architecture than it was originally written for (for example because it assumes the wrong size for 'int'.)
[toc] | [prev] | [next] | [standalone]
| From | Joe Pfeiffer <pfeiffer@cs.nmsu.edu> |
|---|---|
| Date | 2021-04-27 10:03 -0600 |
| Message-ID | <1bv9871zql.fsf@pfeifferfamily.net> |
| In reply to | #160397 |
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. <snip> > I suppose the conclusion is that maybe C code written in the 70's does > compile and work today... but only if it was properly written. If it > wasn't properly written, it's perfectly possible it won't work today, > in a different architecture than it was originally written for > (for example because it assumes the wrong size for 'int'.) Correct (as those of us who are old enough learned in the 80s!).
[toc] | [prev] | [next] | [standalone]
| From | Keith Thompson <Keith.S.Thompson+u@gmail.com> |
|---|---|
| Date | 2021-04-27 09:20 -0700 |
| Message-ID | <871ravbsy3.fsf@nosuchdomain.example.com> |
| In reply to | #160405 |
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.
Everybody who programmed on PDP-11s knew that. There were other
configurations at least as early as K&R1, 1978. But most programmers at
the time probably wouldn't have worked on more than one system.
> <snip>
>
>> I suppose the conclusion is that maybe C code written in the 70's does
>> compile and work today... but only if it was properly written. If it
>> wasn't properly written, it's perfectly possible it won't work today,
>> in a different architecture than it was originally written for
>> (for example because it assumes the wrong size for 'int'.)
>
> Correct (as those of us who are old enough learned in the 80s!).
>
--
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 16:34 +0000 |
| Message-ID | <h2XhI.151573$2A5.5709@fx45.iad> |
| In reply to | #160405 |
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).
[toc] | [prev] | [next] | [standalone]
| From | Joe Pfeiffer <pfeiffer@cs.nmsu.edu> |
|---|---|
| Date | 2021-04-27 10:55 -0600 |
| Message-ID | <1bo8dz1xbq.fsf@pfeifferfamily.net> |
| In reply to | #160407 |
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).
[toc] | [prev] | [next] | [standalone]
Page 3 of 4 — ← Prev page 1 2 [3] 4 Next page →
Back to top | Article view | comp.lang.c
csiph-web