From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from esa2.mentor.iphmx.com (esa2.mentor.iphmx.com [68.232.141.98]) by sourceware.org (Postfix) with ESMTPS id E29253858D38 for ; Tue, 13 Jun 2023 15:10:53 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E29253858D38 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=codesourcery.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=mentor.com X-IronPort-AV: E=Sophos;i="6.00,240,1681200000"; d="scan'208";a="9704223" Received: from orw-gwy-02-in.mentorg.com ([192.94.38.167]) by esa2.mentor.iphmx.com with ESMTP; 13 Jun 2023 07:10:52 -0800 IronPort-SDR: ZO9ni0wj8gy9i0IrWm7VEbF5VZiV/dClQQ7Sqap/OZ0vBA4z2JgvRhKwX9+G3meq91VGvTYzTO hUT3MuEafncwY5ecvP/r0kM0c1EAggGiawaHswgU3nrLNeTSTGum+uCZS6VDEU6+BsDTM4DM72 MTw3QtV/If56ZL5xqvTIjWlHCMFbT0ogC9HExBpRyzTVILD9aYIZMFmwB4496GQmgcRM2ppkq8 +P3XOvypsD6P+ZS4rDCf+gSK71jxdI/AzIX0G6DM/F69cxoEAg5/a5Zq7eYx3KYRe5Ttht3Lpv x7E= Date: Tue, 13 Jun 2023 15:10:48 +0000 From: Joseph Myers To: Jakub Jelinek CC: Marek Polacek , , Subject: Re: [RFC] Add stdckdint.h header for C23 In-Reply-To: Message-ID: References: <68578b43-939-1879-9676-2ea55249a2c5@codesourcery.com> MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" X-Originating-IP: [137.202.0.90] X-ClientProxiedBy: svr-ies-mbx-11.mgc.mentorg.com (139.181.222.11) To svr-ies-mbx-10.mgc.mentorg.com (139.181.222.10) X-Spam-Status: No, score=-3105.8 required=5.0 tests=BAYES_00,HEADER_FROM_DIFFERENT_DOMAINS,KAM_DMARC_STATUS,KAM_NUMSUBJECT,SPF_HELO_PASS,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On Tue, 13 Jun 2023, Jakub Jelinek via Gcc-patches wrote: > There is always the possibility to have the header co-owned by both > the compiler and C library, limits.h style. > Just > #if __has_include_next() > # include_next > #endif > perhaps guarded with some macro at the end of the GCC version and > do the same at the start of the glibc version again perhaps with some macro. > And leave the compiler specific part to the compiler (perhaps with some > fallback in the libc version if the compiler specific part is missing) and > have the library related part be provided by the C library? This seems a reasonable approach. If the structure types do make it into future standard versions, we'd need to work out exactly where the division is between compiler and library header responsibilities (where those pieces involving structure types but not library functions go, for example). For operations using structure types with overflow flag we'd need also to work out to what extent it's appropriate to implement those purely in the header with _Generic versus adding new built-in functions or extending what the existing ones can do. > > > What I'm struggling with is enforcing the weird restrictions > > > C23 imposes on these. > > > > It's not clear all those restrictions need to be enforced - this > > definitely seems like a case of undefined behavior to provide useful > > extension space, where for various of those restrictions there are unique > > sensible semantics to provide if the types in question are supported. > > So why does C2X say > Recommended practice > It is recommended to produce a diagnostic message if type2 or type3 are > not suitable integer types, or if *result is not a modifiable lvalue of > a suitable integer type. > ? > Or is it meant that a suitable integer type doesn't need to be necessarily > one that is listed in the previous paragraph? > Perhaps the checking could be guarded on #ifdef __STRICT_ANSI__, sure... Diagnostics are better than doing something completely random - but making it conditional when there are sensible semantics also makes sense. It seems likely a future standard version will support these operations for bit-precise types, at least. (Bit-precise types are generally tricky for type-generic operations; there's no standard way to select on them with _Generic beyond listing individual types with specific widths, and no standard way to determine the width of the bit-precise type of an argument. So implementing some type-generic operations for such types may need new language extensions, prompting WG14 caution about requiring such support - but this also makes support for such types in standard type-generic macros in headers particularly valuable, precisely because they can't be implemented purely in user code using standard language features.) -- Joseph S. Myers joseph@codesourcery.com