[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: master 37889523278: Add new `swap` macro and use it
From: |
Mattias Engdegård |
Subject: |
Re: master 37889523278: Add new `swap` macro and use it |
Date: |
Sat, 13 Jan 2024 10:50:29 +0100 |
13 jan. 2024 kl. 10.14 skrev Eli Zaretskii <eliz@gnu.org>:
>>> Regardless of portability issues, I think the macro should be called
>>> SWAP, upper-case, to avoid clashes with functions.
I agree, better use upper case here. It's a convention to alert the programmer
and reader that normal evaluation rules don't apply. After all, we don't want
anyone thinking that
SWAP (int, a[i++], a[j++]);
is a good idea. (Maybe we can make it work using preprocessor trickery but I'd
rather not at this point.)
For that matter, we could add code to verify statically that the given type
agrees with that of both arguments.
And I think that a swap macro is useful: in any body of code the probability of
finding the moral equivalent of a botched swap,
a := b;
b := a;
approaches 1 as the code size grows.
Re: master 37889523278: Add new `swap` macro and use it, Stefan Kangas, 2024/01/13
Re: master 37889523278: Add new `swap` macro and use it, Stefan Kangas, 2024/01/06