Path: ...!weretis.net!feeder9.news.weretis.net!news.quux.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: David Brown Newsgroups: comp.lang.c Subject: Re: transpiling to low level C Date: Mon, 23 Dec 2024 13:18:46 +0100 Organization: A noiseless patient Spider Lines: 53 Message-ID: References: <86ikrdg6yq.fsf@linuxsc.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Injection-Date: Mon, 23 Dec 2024 13:18:48 +0100 (CET) Injection-Info: dont-email.me; posting-host="4541fb8706e33f0d382046069d49cfc8"; logging-data="1272736"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19tohY0IY2hc1h1wIXJMpzf4885y9qm/LA=" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.11.0 Cancel-Lock: sha1:BQw6UQYSq9jVADrSzRVD3KS3VYo= In-Reply-To: Content-Language: en-GB Bytes: 3089 On 23/12/2024 12:35, bart wrote: > On 23/12/2024 08:46, David Brown wrote: > >> Tim ruled out &&, ||, ?:, goto, break, continue, if, for, while, >> switch, do, labels, setjmp and longjmp. >> >> He didn't rule out recursion, or the relational operators, or any >> other part of C. >> >> >> int fact(int n); >> >> int fact_zero(int n) { >>          return 1; >> } >> >> int n_fact_n1(int n) { >>          return n * fact(n - 1); >> } >> >> int fact(int n) { >>          return (int (*[])(int)){ fact_zero, n_fact_n1 }[(bool) n](n); >> } >> >> >> There are additional fun things that can be done using different >> operators.  For an unsigned integer "n" that is not big enough to >> wrap, "(n + 2) / (n + 1) - 1"  evaluates "(n == 0)". > > Isn't this just !n ? I don't think "!" was ruled out. This would also > work for negative n. Sure. It was merely another example of something you could use, if you had ruled out simpler things (like the conversion to bool that I used, or the ! operator that you suggest). > >> And Tim did not rule out using the standard library, which would >> surely open up new possibilities. > > printf (not sprintf) would be reasonable here to show results. Anything > else could be considered cheating. > No, I would not say so - as long as the standard library is not ruled out, it is part of C. But I think you could reasonably argue that allowing the standard library makes this whole pointless exercise even more pointless! > The original context was a small subset of C that can be used to > represent a larger subset.