Path: csiph.com!feeder3.eternal-september.org!news.eternal-september.org!eternal-september.org!.POSTED!not-for-mail From: Tim Rentsch Newsgroups: comp.lang.c Subject: Re: transpiling to low level C Date: Tue, 31 Dec 2024 04:57:58 -0800 Organization: A noiseless patient Spider Lines: 51 Message-ID: <86frm4au21.fsf@linuxsc.com> References: <86ikrdg6yq.fsf@linuxsc.com> <20241223134008.000058cf@yahoo.com> <86frmedrof.fsf@linuxsc.com> <865xn3d8lb.fsf@linuxsc.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Date: Tue, 31 Dec 2024 13:57:59 +0100 (CET) Injection-Info: dont-email.me; posting-host="e21c1894af35152a2f46a9d8fe234703"; logging-data="2358940"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/eNDKgnIl9acZZVVg+8Ss4U8y1BDwdjrU=" User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux) Cancel-Lock: sha1:XtGLFTCXLYVoH9sMn66qhYBenYA= sha1:sx2yNBogm81p9ZdRFvlyUMHsKTo= Xref: csiph.com comp.lang.c:389824 BGB writes: > On 12/28/2024 11:24 AM, Tim Rentsch wrote: > >> BGB writes: >> >>> On 12/23/2024 3:18 PM, Tim Rentsch wrote: >>> >>>> Michael S writes: >>>> >>>>> On Mon, 23 Dec 2024 09:46:46 +0100 >>>>> David Brown wrote: >>>>> >>>>>> And Tim did not rule out using the standard library, >>>>> >>>>> Are you sure? >>>> >>>> I explicitly called out setjmp and longjmp as being excluded. >>>> Based on that, it's reasonable to infer the rest of the >>>> standard library is allowed. >>>> >>>> Furthermore I don't think it matters. Except for a very small >>>> set of functions -- eg, fopen, fgetc, fputc, malloc, free -- >>>> everything else in the standard library either isn't important >>>> for Turing Completeness or can be synthesized from the base >>>> set. The functionality of fprintf(), for example, can be >>>> implemented on top of fputc and non-library language features. >>> >>> If I were to choose a set of primitive functions, probably: >>> malloc/free and/or realloc >>> could define, say: >>> malloc(sz) => realloc(NULL, sz) >>> free(ptr) => realloc(ptr, 0) >>> Maybe _msize and _mtag/..., but this is non-standard. >>> With _msize, can implement realloc on top of malloc/free. >>> >>> For basic IO: >>> fopen, fclose, fseek, fread, fwrite >>> >>> printf could be implemented on top of vsnprintf and fputs >>> fputs can be implemented on top of fwrite (via strlen). >>> With a temporary buffer buffer being used for the printed string. >> >> Most of these aren't needed. I think everything can be >> done using only fopen, fclose, fgetc, fputc, and feof. > > If you only have fgetc and fputc, IO speeds are going to be > unacceptably slow for non-trivial file sizes. Once again, any performance concerns are not relevant to the matter under discussion.