Path: csiph.com!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Tim Rentsch Newsgroups: comp.lang.c Subject: Re: transpiling to low level C Date: Sat, 28 Dec 2024 09:24:16 -0800 Organization: A noiseless patient Spider Lines: 41 Message-ID: <865xn3d8lb.fsf@linuxsc.com> References: <86ikrdg6yq.fsf@linuxsc.com> <20241223134008.000058cf@yahoo.com> <86frmedrof.fsf@linuxsc.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Date: Sat, 28 Dec 2024 18:24:17 +0100 (CET) Injection-Info: dont-email.me; posting-host="faac763533e698875b92b0b3d2af3e2e"; logging-data="465100"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+5AsIb9kglDBFiKGp9y41LqMzO02GE8EM=" User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux) Cancel-Lock: sha1:EjV6pI0QdQGKEPnaxlqU1Oi7qGo= sha1:S8DF1lotk+DJOge/EwolHCAsnY8= Xref: csiph.com comp.lang.c:389821 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.