From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 96474 invoked by alias); 8 Mar 2019 00:32:56 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 96396 invoked by uid 89); 8 Mar 2019 00:32:50 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 spammy=noticed X-HELO: mail-wm1-f65.google.com Received: from mail-wm1-f65.google.com (HELO mail-wm1-f65.google.com) (209.85.128.65) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 08 Mar 2019 00:32:49 +0000 Received: by mail-wm1-f65.google.com with SMTP id z84so10962010wmg.4 for ; Thu, 07 Mar 2019 16:32:48 -0800 (PST) Return-Path: Received: from ?IPv6:2001:8a0:f913:f700:4c97:6d52:2cea:997b? ([2001:8a0:f913:f700:4c97:6d52:2cea:997b]) by smtp.gmail.com with ESMTPSA id c17sm10228426wrs.17.2019.03.07.16.32.45 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 07 Mar 2019 16:32:46 -0800 (PST) Subject: Re: [PATCH v2 06/11] Add a more general version of lookup_struct_elt_type. To: John Baldwin , Simon Marchi , gdb-patches@sourceware.org References: <9a5a86e3591c8fe6c0fc8efb6151547902a63d3c.1549672588.git.jhb@FreeBSD.org> <1e84fa17-adf6-186f-843c-e4f7a6dd7e7b@FreeBSD.org> From: Pedro Alves Message-ID: <3de20033-411d-643b-d120-19a49f8815dc@redhat.com> Date: Fri, 08 Mar 2019 00:32:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 MIME-Version: 1.0 In-Reply-To: <1e84fa17-adf6-186f-843c-e4f7a6dd7e7b@FreeBSD.org> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-SW-Source: 2019-03/txt/msg00183.txt.bz2 On 03/08/2019 12:04 AM, John Baldwin wrote: > On 3/7/19 7:53 AM, Simon Marchi wrote: >> Not really a big deal, but I find it a bit overkill to define a type >> just for this, I would have probably just returned the the offset as an >> output parameter. But maybe this way is better, in that if we want to >> add something to the return type, we don't have to update the callers. > > Honestly, I just modeled this after the similar code in the Linux > kernel thread patches. Using a reference parameter for the offset > would be fine and I don't mind making that change. I don't think that > we are going to add more things to that structure in the future. The > field generally has everything else you want to know other than the > offset. > Note that you can keep the struct with just the data fields and no ctor boilerplate if you use brace initialization. I.e., with just: struct struct_elt { /* The field of the element, or NULL if no element was found. */ struct field *field; /* The bit offset of the element in the parent structure. */ LONGEST offset; }; You write: return {nullptr, 0}; return {&TYPE_FIELD (type, i), TYPE_FIELD_BITPOS (type, i)}; Instead of: return struct_elt (); return struct_elt (&TYPE_FIELD (type, i), TYPE_FIELD_BITPOS (type, i)); BTW, I noticed the missing space before parens below: > - return TYPE_FIELD_TYPE (type, i); > + return struct_elt (&TYPE_FIELD(type, i), TYPE_FIELD_BITPOS (type, i)); Thanks, Pedro Alves