From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS22989 209.51.188.0/24 X-Spam-Status: No, score=-4.0 required=3.0 tests=AWL,BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, RCVD_IN_DNSWL_LOW,SPF_HELO_NONE,SPF_PASS shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dcvr.yhbt.net (Postfix) with ESMTPS id 0D1891F45E for ; Mon, 17 Feb 2020 21:19:59 +0000 (UTC) Received: from localhost ([::1]:53222 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j3no5-0007wo-Nj for normalperson@yhbt.net; Mon, 17 Feb 2020 16:19:57 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:42743) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j3no0-0007u5-4E for bug-gnulib@gnu.org; Mon, 17 Feb 2020 16:19:53 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j3nny-00032j-FH for bug-gnulib@gnu.org; Mon, 17 Feb 2020 16:19:51 -0500 Received: from mo6-p01-ob.smtp.rzone.de ([2a01:238:20a:202:5301::7]:28683) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j3nnx-00031x-0N for bug-gnulib@gnu.org; Mon, 17 Feb 2020 16:19:49 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1581974386; s=strato-dkim-0002; d=clisp.org; h=References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: X-RZG-CLASS-ID:X-RZG-AUTH:From:Subject:Sender; bh=4xPLeLkv40jR3IFmfTREK6jLJi5bgDfD4BhVnflVToU=; b=YnUMf86P5FBRiJe6uI31QthXpuzXoQLnutAKXJqlhs/iOwKMZJ4lJhbPlMTi3aXmS+ UvWI4iVmqQ8vexu4p1F+QhbbYUROsdUcF57/13innI1log5ptqlsdi5y91OxI07KdgiT q62JzjFEy5v3dVn+oDqqTBfe8jzAGjKwHVgIiX6KpxfYmJCOu2gzwM5JThbHDVVCDwUV xOTXdVBQnAmTK2MpJ2wkMdk/OzvSXy03aTGp8b7bOq8PtBuvVIqcHkgmHIIrkZ50gRtm Mg1Pr5dxkEQm6aOEnlsHDo5fMgYTUKIVF8BVEJAghtw7/iPkUA/qkTAI/nq14PmCxkBt Lvug== X-RZG-AUTH: ":Ln4Re0+Ic/6oZXR1YgKryK8brlshOcZlIWs+iCP5vnk6shH+AHjwLuWOH6fzxfs=" X-RZG-CLASS-ID: mo00 Received: from bruno.haible.de by smtp.strato.de (RZmta 46.1.12 DYNA|AUTH) with ESMTPSA id g00701w1HLJiJje (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (curve X9_62_prime256v1 with 256 ECDH bits, eq. 3072 bits RSA)) (Client did not present a certificate); Mon, 17 Feb 2020 22:19:44 +0100 (CET) From: Bruno Haible To: bug-gnulib@gnu.org Subject: Re: restrict - summary Date: Mon, 17 Feb 2020 22:19:44 +0100 Message-ID: <5207910.RxYcQDdI9g@omega> User-Agent: KMail/5.1.3 (Linux/4.4.0-171-generic; KDE/5.18.0; x86_64; ; ) In-Reply-To: <1751343.mXlyrFEpWx@omega> References: <20200209144434.GA19087@aun.utmark.mea> <1751343.mXlyrFEpWx@omega> MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a01:238:20a:202:5301::7 X-BeenThere: bug-gnulib@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Gnulib discussion list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Tim =?ISO-8859-1?Q?R=FChsen?= , Mats Erik Andersson Errors-To: bug-gnulib-bounces+normalperson=yhbt.net@gnu.org Sender: "bug-gnulib" Thanks to Paul and all for the enlightening discussion about what 'restrict' actually means. What I intend to do it gnulib is: * In the function *definitions*, do not use 'restrict' at all. Rationale: - Gnulib code is not time-critical. 'restrict' enables micro- optimizations, at the price of undefined behaviour for some callers. - Humans have a poor understanding of what 'restrict' means, and the GCC warnings cover only a subset of the undefined behaviour situations (namely, GCC can only warn about equal pointers, but not about overlapping array slices). * In the function *declarations* for POSIX functions, I will use 'restrict' exactly as written in POSIX. Rationale: - 'restrict' modifies the contract between the caller and the implementor of a function. Whatever 'restrict' precisely means, the contract that programmers will look at is the POSIX standard. * In the function *declarations* for non-POSIX functions, I will use 'restrict' when there is a significant benefit, and only on non-const pointer parameters. Rationale: - I want to see useful warnings from GCC. "Useful" means: with the normal programming style; passing 'void *' arguments to functions that expect 'char *', 'FILE *', etc. is not the normal programming style I want to care about. - The semantics of 'restrict' is a bit confusing, and the semantics of 'restrict' on const pointer parameters is additionally confusing. - It is typically sufficient - both for warnings and optimization - to put 'restrict' on the non-const pointer parameters only. Bruno