From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.devel Subject: Re: master 37889523278: Add new `swap` macro and use it Date: Sat, 06 Jan 2024 10:44:02 +0200 Message-ID: <83o7dyua0d.fsf@gnu.org> References: <170452579053.27998.16123231327386305897@vcs2.savannah.gnu.org> <20240106072311.28B8FC0034E@vcs2.savannah.gnu.org> <87plye9ahs.fsf@yahoo.com> Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="8706"; mail-complaints-to="usenet@ciao.gmane.io" Cc: emacs-devel@gnu.org, stefankangas@gmail.com To: Po Lu Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Sat Jan 06 09:44:57 2024 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1rM2IZ-00024f-Nv for ged-emacs-devel@m.gmane-mx.org; Sat, 06 Jan 2024 09:44:55 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rM2Ht-0005kf-KJ; Sat, 06 Jan 2024 03:44:13 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rM2Hs-0005kF-9R for emacs-devel@gnu.org; Sat, 06 Jan 2024 03:44:12 -0500 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rM2Hs-0005gC-0q; Sat, 06 Jan 2024 03:44:12 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=References:Subject:In-Reply-To:To:From:Date: mime-version; bh=Pvbb25E+N8wC7Ny2RmKYrtF0fIFsSuJTZFk9hJjwam8=; b=NUSv+aigy/eP UgQDvnb7Tzl3MQS/TX+8gXu9lXW9YWJM4M2hI3VeJA7ryBCynezmj0faF5dAnelEOBkyCoG08PU+4 Qhht/pEwWzyV+TfisPu1n/kDDht4zeezTeOHb8SRY+uwZM8hdO3gyJhepN/lYkR8Z6/dbVeGEcphK uXt6T01Dglf/O2bez48Wph4hkfNXJEI0iH0RyWiZ8WgwDpnFwKRukUZZ3XRm9X9scgEatOlD57r4a Fmck5EyDKRvt0igTNoy6CTndeG+Y/S78dlzffKpMUrA/GmqVvFVUPODneDnOTD/tQKjzsfsVQM9ZF yH0Z0xZmp5Ni4cPQf/03lA==; In-Reply-To: <87plye9ahs.fsf@yahoo.com> (message from Po Lu on Sat, 06 Jan 2024 15:39:11 +0800) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.devel:314596 Archived-At: > From: Po Lu > Cc: Stefan Kangas > Date: Sat, 06 Jan 2024 15:39:11 +0800 > > Stefan Kangas writes: > > > branch: master > > commit 37889523278fe65733938fb11c3701898309961c > > Author: Stefan Kangas > > Commit: Stefan Kangas > > > > 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.