Source-Changes-D archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: CVS commit: src/bin/sh



Am 10.10.2021 um 08:40 schrieb Tom Ivar Helbekkmo:
> Roland Illig <rillig%netbsd.org@localhost> writes:
>
>> sh: ignore lint error about 'continue' in 'do while' loop
>>
>> exec.c(575): error: continue in 'do ... while (0)' loop [323]
>> jobs.c(203): error: continue in 'do ... while (0)' loop [323]
>>
>> It is certainly a rarely used feature, I saw it the first time today
>> and I don't see why a 'continue' statement in a 'do while' loop should
>> be an error.
>
> The only reason I can think of for using a 'do ... while (0)' construct
> outside of a '#define' is to have a block that's executed once, but that
> you can break out of without having to use 'goto'.  When you do this,
> the keywords 'break' and 'continue' both break out of the block.  I
> guess what lint is saying here is that because of this, you should use
> 'break', and not 'continue', to make it explicit what's happening.

Perfect guess, that's exactly the reason, as stated in
https://github.com/NetBSD/src/commit/d4d6980a4bb5db5188b919db from
2008-07-25.

At that time, the test suite for lint didn't contain a test for a
do-while-0 loop containing a switch statement containing a continue
statement, and this case where continue is actually different from break
was probably not on the author's mind.

I had not looked up the history of the message yesterday since I assumed
this error message had been there from the beginning. I should have
known the message ID 323 better since that looks really high. Oh well,
on a second look it's not that high either since even in 1995 there were
already the messages from 0 to 309.

Anyway, the code in question was more verbose than necessary, so I made
it simpler. I also experimented with replacing the switch with a single
if statement, but that would have become too dense and thus difficult to
decipher.

Roland


Home | Main Index | Thread Index | Old Index