Groups | Search | Server Info | Login | Register
Groups > comp.lang.c > #397387
| From | Tim Rentsch <tr.17687@z991.linuxsc.com> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: Sort of trivial code challenge - may be interesting to you anyway |
| Date | 2026-04-06 12:02 -0700 |
| Organization | A noiseless patient Spider |
| Message-ID | <86se97zzcu.fsf@linuxsc.com> (permalink) |
| References | (7 earlier) <865x718b5q.fsf@linuxsc.com> <10p0u54$32bhs$1@dont-email.me> <10p24th$3mc94$1@dont-email.me> <86h5qg66v7.fsf@linuxsc.com> <10p7g4c$1haut$1@dont-email.me> |
Bart <bc@freeuk.com> writes:
> On 15/03/2026 22:54, Tim Rentsch wrote:
>
>> Bart <bc@freeuk.com> writes:
>>
>>> On 13/03/2026 11:58, Bart wrote:
>>>
>>> [characterizing my earlier code as a finite state machine]
>>>
>>>> Ideally it would just have a loop. (In my languages, there is a
>>>> feature called 'doswitch',
>>>
>>> I ported this (C version using 'goto') to my scripting language just
>>> to see what it would look like:
>>>
>>> https://github.com/sal55/langs/blob/master/tr.q
>>>
>>> This doesn't use 'goto', nor conventional loops. However 'doswitch'
>>> does loop.
>>>
>>> An alternative method could use 'recase' (in C terms, jumping directly
>>> to a case label). It's just goto 'under the hood', but much less
>>> underhand than 'longjmp'.
>>>
>>> Other ways of control flow include label pointers (also in some C
>>> extensions).
>>
>> None of these more elaborate control structures are needed. The
>> board display behavior can easily be expressed using conventional
>> control structures, in standard C:
>>
>> void
>> show_board( unsigned height, unsigned width, unsigned cutoff ){
>> const int D = digits_width( cutoff );
>> const unsigned R = cutoff < height ? cutoff : height;
>> unsigned r = 0, c = 0;
>>
>> while( r < R ){
>> unsigned v = r + c*height;
>> if( v < cutoff ) printf( " %*u", D, v+1 );
>> if( ++c >= width ) putchar( '\n' ), c = 0, r++;
>> }
>> }
>
> Yes, but you'd prohibited many standard features including loops for
> your challenge.
I was responding to a context where the prohibitions had already
been violated. I was simply pointing out that if those rules are
going to be ignored then there are easier ways to solve the problem
than importing exotic control structures from other languages.
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar
Re: Sort of trivial code challenge - may be interesting to you anyway Tim Rentsch <tr.17687@z991.linuxsc.com> - 2026-03-12 05:50 -0700
Re: Sort of trivial code challenge - may be interesting to you anyway Bart <bc@freeuk.com> - 2026-03-13 11:58 +0000
Re: Sort of trivial code challenge - may be interesting to you anyway Bart <bc@freeuk.com> - 2026-03-13 23:00 +0000
Re: Sort of trivial code challenge - may be interesting to you anyway Tim Rentsch <tr.17687@z991.linuxsc.com> - 2026-03-15 15:54 -0700
Re: Sort of trivial code challenge - may be interesting to you anyway Bart <bc@freeuk.com> - 2026-03-15 23:42 +0000
Re: Sort of trivial code challenge - may be interesting to you anyway Tim Rentsch <tr.17687@z991.linuxsc.com> - 2026-04-06 12:02 -0700
Re: Sort of trivial code challenge - may be interesting to you anyway Tim Rentsch <tr.17687@z991.linuxsc.com> - 2026-03-15 15:43 -0700
csiph-web