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: Using static_assert in Emacs? Date: Thu, 18 Jul 2024 20:35:44 +0300 Message-ID: <865xt2fvrj.fsf@gnu.org> References: <867cdig0zu.fsf@gnu.org> Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="13334"; mail-complaints-to="usenet@ciao.gmane.io" Cc: emacs-devel@gnu.org, eggert@cs.ucla.edu To: Stefan Kangas Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Thu Jul 18 19:36:36 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 1sUV3T-0003Ce-Ri for ged-emacs-devel@m.gmane-mx.org; Thu, 18 Jul 2024 19:36:36 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sUV32-0007NE-BS; Thu, 18 Jul 2024 13:36:12 -0400 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 1sUV2l-0007Em-6V for emacs-devel@gnu.org; Thu, 18 Jul 2024 13:35:51 -0400 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 1sUV2h-0004Vn-V4; Thu, 18 Jul 2024 13:35:48 -0400 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=NoY80axYBgt1b8fnS4YGcbQmN0dZ/5svJptVhD3veVg=; b=NijQs/cc/px5 SlhMm7kZd3nB713Xpfjbr3zWteCUxMFJgk/tL9s/WruB5Gki6Vpq1V8jO/hBADS0heffeQW3l0ATl ldgYXJrOi2ofxKc6bCG3UGsTRilIo2R74epYO4bUFEH2ivFrevE4St0ZaNXsRYosNrXVVf+TIbs4t Peos+BsYv/bVT6AydLdXfskhDwC3dhERx19wI0GWliaxU1di0XKGEC/ssCe99UoIIyP+tOpDLC2Ur jHGDs1pGYXqzOY1qpTc+aqhMqpTUTwLRIZkURfD3qY3/wrswb55XOI0bIRp8ftDymB/o6QTneAnQk fWXKVEEebV74ndiaF/iZ4g==; In-Reply-To: (message from Stefan Kangas on Thu, 18 Jul 2024 09:39:43 -0700) 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:321804 Archived-At: > From: Stefan Kangas > Date: Thu, 18 Jul 2024 09:39:43 -0700 > Cc: emacs-devel@gnu.org, eggert@cs.ucla.edu > > Eli Zaretskii writes: > > > We already have it in config.h, so we can use it. (Gnulib actually > > uses it, see lib/*.c.) > > Good to know, thanks. > > > The real question is: where and how will that be useful? > > I'm looking at something like this, where the sizes are known at compile > time: > > #define FOO "some text" > static_assert (sizeof buf >= sizeof FOO); > memcpy (buf, FOO, sizeof FOO); If we have such code (do we?), and if there's a danger that someone makes FOO longer but forgets to change buf, such an assertion could be useful. IME, such code is rare, though.