From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm1-x341.google.com (mail-wm1-x341.google.com [IPv6:2a00:1450:4864:20::341]) by sourceware.org (Postfix) with ESMTPS id 466E5384BC3C for ; Mon, 21 Sep 2020 12:47:54 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 466E5384BC3C Received: by mail-wm1-x341.google.com with SMTP id b79so12523560wmb.4 for ; Mon, 21 Sep 2020 05:47:54 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=fXW/jSQ22/9lW7spsn+HohwO5cavybZF+AnRokgGgKs=; b=i6I5tO9WoxihPd2j6wWxU/t35iNl+pGr2p/TKFHgYHMwGofT9G3C5ymn6x6jkOUYre YxZ/YsI6cAb/q5KvDQEESRqQA5MdK5jPo9fBuZvAoizpgjY7g+mWqGNmjXDaURzn9UKg nPL/6Ny4xdJrxJh/kNoCOPPBxRn9CzA4bteSp0VoJfeHps8AkgVRHq1pP9Gw1Ctyqm7C zl6NaqCXaktN4xUv+7skLyn1ScWZ+jHoRbuWVCY8mXYdGJjNpt6n9ZacOsLjwkzZnJ66 It97C4t5vHZttXCiXKzcnYRlgfAxHChew3MviKpWxfcSz3NGYWh9U6ZBPASHT1mGCa0t svjQ== X-Gm-Message-State: AOAM533j1cxKJnjP+LLe9hRuaIYrgTplVSBd+OHWm408HbCGtt9CE2K0 TgcGHHj778/9Mi6u5B6UOiI= X-Google-Smtp-Source: ABdhPJzYlhKGTFZGE9SLL/+DmPWodg5weqV76uYe9Qy1vbHQyy4cwgiVrsExQixmCPugml0aPWULOg== X-Received: by 2002:a1c:408a:: with SMTP id n132mr29094058wma.45.1600692473387; Mon, 21 Sep 2020 05:47:53 -0700 (PDT) Received: from [192.168.1.143] ([170.253.60.68]) by smtp.gmail.com with ESMTPSA id t16sm21147607wrm.57.2020.09.21.05.47.52 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 21 Sep 2020 05:47:52 -0700 (PDT) Subject: Re: Expose 'array_length()' macro in or To: Florian Weimer Cc: Libc-alpha , gcc@gcc.gnu.org, libstdc++@gcc.gnu.org, libc-coord@lists.openwall.com References: <946e9377-0558-3adf-3eb9-38c507afe2d0@gmail.com> <874knr8qyl.fsf@oldenburg2.str.redhat.com> <875z875si2.fsf@oldenburg2.str.redhat.com> From: Alejandro Colomar Message-ID: Date: Mon, 21 Sep 2020 14:47:51 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.12.0 MIME-Version: 1.0 In-Reply-To: <875z875si2.fsf@oldenburg2.str.redhat.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM, NICE_REPLY_A, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 21 Sep 2020 12:48:01 -0000 [[ CC += libc-coord at lists.openwall.com ]] On 2020-09-21 12:33, Florian Weimer wrote: > * Alejandro Colomar: > >> [[ >> CC += libc-coord at sourceware.org >> CC += gcc at gcc.gnu.org >> CC += libstdc++ at gcc.gnu.org >> ]] >> >> Hi Florian, >> >> On 2020-09-21 10:38, Florian Weimer wrote: >>> * Alejandro Colomar via Libc-alpha: >>> >>>> I'd like to propose exposing the macro 'array_length()' as defined in >>>> 'include/array_length.h' to the user. >>> >>> It would need a good C++ port, probably one for C++98 and another one >>> for C++14 or later. >> >> For C++, I use the following definition: >> >> >> #include >> #include >> #include >> >> >> #define is_array__(a) (std::is_array <__typeof__(a)>::value) > > Should be decltype. Thanks. > >> However, there are a few problems: >> >> 1) This doesn't work for VLAs (GNU extension). >> I couldn't find a way to do it. Maybe I should file a bug in GCC. > > I do not think VLA support is critical. C++ programmers will be used to > limited support in utility functions. > >> 2) Also, this requires C++11; I don't know how to do it for older C++. >> Again, support from the compiler would be great. > > I think limited C++98 support is possible using a function template, > where the array length N is a template parameter. To enable use in > constant expressions, you can return a type of char[N], and the macro > wrapper should then apply sizeof to the function result. Sorry, I don't know much C++, and I don't know how to do this. > >> 3) The macro can't be used in the same places as the C version, >> because of the `({})`. >> The `0 * sizeof(struct{...})` trick doesn't work in C++ due to: >> error: types may not be defined in 'sizeof' expressions > > For C++11, you can use a constexpr function instead of a macro. > > array_length should not be a macro in current C++ modes, so that we > retain compatibility if a future C++ standard adds array_length (or > nitems) on its own. This is not a concern for legacy C++98 mode. See above. > >>> Maybe also ask on the libc-coord list. >> >> Ok. Added CCs. > > libc-coord is not hosted on sourceware: > > > > The discussion here veered off into C++ territory anyway. I added the correct list now. > > Thanks, > Florian > Thanks, Alex.