emacs-devel
[Top][All Lists]
Advanced

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

Re: master 37889523278: Add new `swap` macro and use it


From: Po Lu
Subject: Re: master 37889523278: Add new `swap` macro and use it
Date: Mon, 08 Jan 2024 10:15:02 +0800
User-agent: Gnus/5.13 (Gnus v5.13)

Stefan Kangas <stefankangas@gmail.com> writes:

> Anyways, the comp.lang.c FAQ entry you quoted here does not discuss the
> typeof operator.  That has been changed in more recent versions.

It makes unambiguous reference to the bearing of typeof:

10.3: How can I write a generic macro to swap two values?

A: There is no good answer to this question.  If the values are
integers, a well-known trick using exclusive-OR could perhaps be used,
but it will not work for floating-point values or pointers, or if the
two values are the same variable.  (See questions 3.3b and 20.15c.)  If
the macro is intended to be used on values of arbitrary type (the usual
goal), it cannot use a temporary, since it does not know what type of
temporary it needs (and would have a hard time picking a name for it if
it did), and standard C does not provide a typeof operator.
                                           ------

Nothing in this respect has changed since this was written: Standard C
won't provide a typeof operator until later this year, and it will be
decades before it will be universally available to programs.  For that
matter, what are we arguing over?  Is it really this hard to agree on
the two facts that typeof is not portable, by our standards of
portability (C99, and various operating systems), and macros with which
invocation errors cannot be detected except on a handful of
little-tested systems are liable to produce many such errors, much like
GCPRO once did?

Both statements have been accepted wisdom where C development is
concerned for quite a while now, and we have direct experience with the
latter, which was reason enough to remove the problematic macro.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]