[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: master 37889523278: Add new `swap` macro and use it
From: |
Eli Zaretskii |
Subject: |
Re: master 37889523278: Add new `swap` macro and use it |
Date: |
Sat, 06 Jan 2024 10:44:02 +0200 |
> From: Po Lu <luangruo@yahoo.com>
> Cc: Stefan Kangas <stefankangas@gmail.com>
> Date: Sat, 06 Jan 2024 15:39:11 +0800
>
> Stefan Kangas <stefankangas@gmail.com> writes:
>
> > branch: master
> > commit 37889523278fe65733938fb11c3701898309961c
> > Author: Stefan Kangas <stefankangas@gmail.com>
> > Commit: Stefan Kangas <stefankangas@gmail.com>
> >
> > Add new `swap` macro and use it
> >
> > A `swap` macro prevents programming errors and is more concise.
> > It is a natural addition to our existing `min` and `max` macros.
>
> It's well known that a generic "swap" macro is impossible to express in
> Standard C for lack of a standard "typeof"-like expression. To
> compensate for this limitation, the macro must accept an argument
> identifying the type of the field where the temporary value is saved,
> which is more trouble than it's worth and reintroduces the type
> conversion problems such macros are intended to prevent.
>
> Neither typeof nor __typeof__ are portable by our standards, the latter
> being an extension compatible with the Standard enabled when GCC is
> configured to obey the standard to the letter, while the former is a
> keyword enabled in other situations.
Regardless of portability issues, I think the macro should be called
SWAP, upper-case, to avoid clashes with functions.
- Re: master 37889523278: Add new `swap` macro and use it, Po Lu, 2024/01/06
- Re: master 37889523278: Add new `swap` macro and use it,
Eli Zaretskii <=
- Re: master 37889523278: Add new `swap` macro and use it, Po Lu, 2024/01/06
- Re: master 37889523278: Add new `swap` macro and use it, Stefan Kangas, 2024/01/06
- Re: master 37889523278: Add new `swap` macro and use it, Po Lu, 2024/01/06
- Re: master 37889523278: Add new `swap` macro and use it, Stefan Kangas, 2024/01/06
- Re: master 37889523278: Add new `swap` macro and use it, Po Lu, 2024/01/06
- Re: master 37889523278: Add new `swap` macro and use it, Eli Zaretskii, 2024/01/06
- Re: master 37889523278: Add new `swap` macro and use it, Po Lu, 2024/01/06
- Re: master 37889523278: Add new `swap` macro and use it, Eli Zaretskii, 2024/01/06
- Re: master 37889523278: Add new `swap` macro and use it, Po Lu, 2024/01/06
- Re: master 37889523278: Add new `swap` macro and use it, Stefan Kangas, 2024/01/07