On Tue, Dec 17, 2024 at 04:18:17PM -0500, Greg Wooledge wrote:
> On Tue, Dec 17, 2024 at 16:09:09 -0500, Jeffrey Walton wrote:
> > I would rewrite the cleanup code like so:
> >
> > void dealloc()
> > {
> > DIGIT *next, *p = head;
> > while( p )
> > next = p->next, free( p ), p = next;
> > }
>
> The logic looks good, but I'm not a fan of this use of the comma operator.
> Is that a fashionable thing nowadays?
>
> Especially when teaching a new programmer the ropes, I would stick with
> the regular syntax.
>
> void dealloc() {
> DIGIT *next, *p = head;
> while (p) {
> next = p->next;
> free(p);
> p = next;
> }
> }
>
> You can put the opening { on the next line if you prefer that way. I
> know some people have very strong feeling about that.
The comma saves the braces, but then, this might be a Bad Thing, as
Apple learnt the hard way a couple of years ago [1] :-)
Now taking my tongue out-of-cheek, I'd prefer your code, too. Much
clearer and much less hidden footguns.
I'm all for concise code, but I usually revert some things in a second
pass when they seem to hurt clarity. After all, you write your code for
other people to read it.
Cheers
[1] https://dwheeler.com/essays/apple-goto-fail.html
--
t
Attachment:
signature.asc
Description: PGP signature