From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 58F953858D28 for ; Mon, 4 Dec 2023 18:51:49 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 58F953858D28 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 58F953858D28 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701715910; cv=none; b=iIdswz7hfeqZaOmx89GuFzy3a3itl+BqnfO80mq4uLOdof2UfncRMNPIMRGb32U9jiM5F9J16mcFxwV2owAF8faW4xEjIwhB6ANZydfAGrX57NBfrXvGjFAsvSUwrQMh3Nz4WzzbN7tE8FAniFiEpv6Jct8PLkYte6mQ5zhHHmA= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701715910; c=relaxed/simple; bh=Xe7jw3T0nGVoQTWvktgGLMY0eaNmu0bC81WrX/FKkV8=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=chJ2gf5Yhc7LOVkUl5TQGEIrnC+3an6Onuf9ubQOFN/ophbyZyQR4zy1OFuS//CJ56Owrfy3IUkYfwGCDODX0dimfWxUqTb0ck1WgmQyi0zmPJFb7u2pdJl3+a3FD7zJohfSeldqT304YxeM4qZ3KmFnQ8sFP8UzYhR+lc8XLMY= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1701715908; h=from:from:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:in-reply-to:in-reply-to: references:references; bh=cb+3wjWHn+mnv5IWH6gFIpBL/mu170mEVoMOaQSORcs=; b=JWfL5sIcu/SQvRDukIsSPMrN/5VhgO8/xAWGMevBHgmwd9wOiJpf6Ktv2MUJlJcF3Tj3il LV2gzPa8OEVzojcXAg1vnN69mU2iX1u2xyPyLinaAgoTnMx+e/cn6lK985Q61ELtbs9yKW AoBfyt9Pp6QDn6TiA5xrp3Qm98C547E= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-252-NCQoWzZ3ORSMgp_ZZSqukQ-1; Mon, 04 Dec 2023 13:51:46 -0500 X-MC-Unique: NCQoWzZ3ORSMgp_ZZSqukQ-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 4876B88D017; Mon, 4 Dec 2023 18:51:46 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.195.157]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 92A1136E2; Mon, 4 Dec 2023 18:51:39 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.17.1/8.17.1) with ESMTPS id 3B4Ipa5e2170394 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Mon, 4 Dec 2023 19:51:36 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 3B4IpYKF2170393; Mon, 4 Dec 2023 19:51:34 +0100 Date: Mon, 4 Dec 2023 19:51:34 +0100 From: Jakub Jelinek To: Siddhesh Poyarekar Cc: Martin Uecker , Andreas Schwab , polacek@redhat.com, gcc-patches@gcc.gnu.org Subject: Re: [gcc15] nested functions in C Message-ID: Reply-To: Jakub Jelinek References: <7862c488-5afd-4018-9dc5-c72d9382a052@gotplt.org> <48690099bc3fb6030191d2c58525fcfc415da107.camel@tugraz.at> <3b959c8a-0a65-4185-a943-122bb898796f@gotplt.org> MIME-Version: 1.0 In-Reply-To: <3b959c8a-0a65-4185-a943-122bb898796f@gotplt.org> X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Spam-Status: No, score=-3.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE,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: On Mon, Dec 04, 2023 at 01:27:32PM -0500, Siddhesh Poyarekar wrote: > [Branching this into a separate conversation to avoid derailing the patch, > which isn't directly related] > > On 2023-12-04 12:21, Martin Uecker wrote: > > I do not really agree with that. Nested functions can substantially > > improve code quality and in C can avoid type unsafe use of > > void* pointers in callbacks. The code is often much better with > > nested functions than without. Nested functions and lambdas > > (i.e. anonymous nested functions) are used in many languages > > because they make code better and GNU's nested function are no > > exception. > > > > So I disagree with the idea that discouraging nested functions leads > > to better code - I think the exact opposite is true. > > I would argue that GNU's nested functions *are* an exception because they're > like feathers stuck on a pig to try and make it fly; I think a significant > specification effort is required to actually make it a cleanly usable > feature. Why? The syntax doesn't seem to be something unexpected, and as C doesn't have lambdas, one can use the nested functions instead. The only problem is if you need to pass function pointers somewhere else (and target doesn't have function descriptors or something similar), if it is only done to make code more readable compared to say use of macros, I think the nested functions are better, one doesn't have to worry about multiple evaluations of argument side-effects etc. And if everything is inlined and SRA optimized, there is no extra cost. The problem of passing it as a function pointer to other functions is common with C++, only lambdas which don't capture anything actually can be convertible to function pointer, for anything else you need a template and instantiate it for a particular lambda (which is something you can't do in C). Jakub