Path: csiph.com!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: Tim Rentsch
Newsgroups: comp.lang.c
Subject: Re: Programming exercise/challenge
Date: Tue, 29 Dec 2020 19:59:29 -0800
Organization: A noiseless patient Spider
Lines: 33
Message-ID: <86mtxwueou.fsf@linuxsc.com>
References: <86wnxwkyol.fsf@linuxsc.com> <86sg7uygsg.fsf@linuxsc.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Injection-Info: reader02.eternal-september.org; posting-host="bad9f3398650fdf0e991b5310f5ac4d7"; logging-data="15117"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/ewoyVL07HQNUuFPeqO7pRGsUHBPIyQJA="
User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux)
Cancel-Lock: sha1:bCirIZC55aOM2mcneH37OwTEiAo= sha1:t/tBJpZgM2XZevPk6ZzQjn5mJmQ=
Xref: csiph.com comp.lang.c:157880
kegs@provalid.com (Kent Dickey) writes:
> In article ,
> Kent Dickey wrote:
>
>> Here's my (hopefully last) attempt.
>>
>> Now, I've optimized the main loop so it should be about as fast as
>> possible until a /, ", or ' is seen, then it does the slow
>> processing to get things right until the quote or comment ends. In
>> the main loop, it's basically if(array[c = getchar()]) putchar(c).
>> If that's not fast enough, you'd have to roll your own
>> putchar()/getchar().
>>
>> It's a different approach--now multiple subroutines call
>> getchar()/putchar(). I like it better in some ways, but I don't
>> love it.
>>
>> It passes my simple tests, but there are probably still bugs. This
>> is tricky enough that a good test suite is needed.
>
> Well, this is embarrassing. It fails on ITSELF. I forgot to reset
> the backslash count inside strings when a non-backslash is seen, so
> for this line:
>
> putchar('\n'); // comment
>
> it didn't remove the comment.
>
> [...]
This latest version matches my reference implementation on
the standard test input I've been using. Just FYI.