From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-40140.protonmail.ch (mail-40140.protonmail.ch [185.70.40.140]) by sourceware.org (Postfix) with ESMTPS id ADB2A3858D35 for ; Wed, 28 Jun 2023 09:56:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org ADB2A3858D35 Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=protonmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=protonmail.com Date: Wed, 28 Jun 2023 09:56:48 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail3; t=1687946210; x=1688205410; bh=Fdynb22S34jWanwjqz4rJ9+Ph2248lIYrDXDGrS7bR0=; h=Date:To:From:Cc:Subject:Message-ID:In-Reply-To:References: Feedback-ID:From:To:Cc:Date:Subject:Reply-To:Feedback-ID: Message-ID:BIMI-Selector; b=sPDC3HNuv2UPsGU8y+S0lTcgtI1gNj1heOlscpinhp1niaM40BJkhNC0bnYgDScWq tQofjEjTyd3eQi9WQsdYgS9dbfb6aMElJ6lOL/En7ZWcy7iivEUd5Zfgdv3rQdjyh+ 7AgLgBn2DRkiyB/f+B6OleoMWe8HSghyHrKBhHrEJE0qTFjE1PIkZHv2e2G6fZU/PC lK6VukGpsIoj5KFLlsvO76fXHNFPgFb6O06Z1EyseCa1ozghr3nHvkd3Uy3Lti84/i Etyd6jMU8NV21tY7mDK30FDj5aA3JEJ/X20dj6VnYrHZ+rAQHhzcHSLVQgxF7A1IAi a7c7b19KNHJQA== To: =?utf-8?Q?Rafa=C5=82_Pietrak?= From: waffl3x Cc: Jonathan Wakely , "gcc@gcc.gnu.org" Subject: Re: wishlist: support for shorter pointers Message-ID: In-Reply-To: <21650b1b-1d2e-7929-3105-b8aaca629272@ztk-rp.eu> References: <439affd4-11fe-de80-94c8-6fc64cbf76ec@ztk-rp.eu> <21650b1b-1d2e-7929-3105-b8aaca629272@ztk-rp.eu> Feedback-ID: 14591686:user:proton MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Here's a quick and dirty example of how this function could be rewritten wi= th modern C++. I omitted some necessary details, particularly the implementati= on of the linked list iterator. I also wrote it out quickly so I can't be certain it'= s 100% correct, but it should give you an idea of whats possible. // I assume you meant to return a pointer template auto test_funct(Iter iter, Iter end, char opt) { for (; iter !=3D end; ++iter) { // dereferencing iter would get buff if (!*iter) { *iter =3D opt; break; } } return iter; } I also made an example using the C++ algorithms library. template auto test_funct(Iter begin, Iter end, char opt) { auto iter =3D std::find_if(begin, end, [](auto buff){return !buff;}); if (iter) { *iter =3D opt; } return iter; } As I said, there's quite a bit omitted here, to be blunt, implementing both the fancy pointers (especially when I don't know anything about the hardwar= e) and the iterators required would be more of a task than I am willing to do. I'm= happy to help but I don't think I should be doing unpaid labor :). These examples would work with anything implementing the C++ iterator interface, as long as you conform to that interface on both sides, most cod= e will be reusable where it is possible. Regarding the C++ runtime, I can't speak authoritatively, but I believe tha= t the C++ runtime is fairly hefty yes. Luckily, plenty of the standard librar= y does not require it. I believe you'll want to look into GCC's freestanding suppo= rt to get a full picture of what is and is not available. Again, I can't speak authoritatively on the matter, but I think you would be correct to avoid th= e C++ runtime. There are other pitfalls to beware of, one of my concerns is that templates= can cause some degree of bloat to executable size, I imagine one can get around= it if they try hard enough though. The most real bottleneck you'll encounter in v= ery large projects is compile time, but that all depends on what you're using, = and how much you're using it, and even then there are mitigations for that. I'm happy to answer more questions and help, however I'm concerned this is getting fairly unrelated to GCC. -Alex