Re: Expose 'array_length()' macro in or

2020-09-30 Thread Alejandro Colomar via Gcc
On 2020-09-30 17:58, Joseph Myers wrote: For some reason http://www.open-std.org/jtc1/sc22/wg14/www/docs/n2529.pdf doesn't seem to have reached the agenda of a WG14 meeting yet, but adding a language feature like that to the standard would be another approach. Hi Joseph, Yes, that would be

Re: [libc-coord] Re: Expose 'array_length()' macro in or

2020-09-22 Thread Ville Voutilainen via Gcc
On Tue, 22 Sep 2020 at 19:46, Jonathan Wakely via Libstdc++ wrote: > > On 22/09/20 12:25 -0400, Rich Felker wrote: > >Is there really a reason to want a nonstandard macro like this to do > >something that's already trivial to do in the base language and has a > >standard idiom (sizeof x / sizeof *

Re: [libc-coord] Re: Expose 'array_length()' macro in or

2020-09-22 Thread Jonathan Wakely via Gcc
On 22/09/20 12:25 -0400, Rich Felker wrote: Is there really a reason to want a nonstandard macro like this to do something that's already trivial to do in the base language and has a standard idiom (sizeof x / sizeof *x)? IMHO no.

Re: [libc-coord] Re: Expose 'array_length()' macro in or

2020-09-22 Thread Rich Felker
On Mon, Sep 21, 2020 at 02:47:51PM +0200, Alejandro Colomar wrote: > [[ CC += libc-coord at lists.openwall.com ]] I missed the beginning of this so perhaps it's already been discussed, but I don't see how cdefs.h is a remotely reasonable place for this. cdefs.h is included by all glibc headers and

Re: Expose 'array_length()' macro in

2020-09-22 Thread Florian Weimer via Gcc
* Ville Voutilainen: > Why should this be array_length and not __array_length? This is a > vendor extension, so it should use > a name that is reserved for such? In general, we use __ for glibc internals that are not intended for direct access by users. In some cases, we have non-__ identifiers

Re: Expose 'array_length()' macro in

2020-09-22 Thread Alejandro Colomar via Gcc
Thanks again for your improvements. I think this might be ready for a patch already. Any more thoughts? Thanks, Alex #if defined(__cplusplus) # include # if __cplusplus >= 201103L template constexpr inline std::size_t __array_length(const _Tp(&)[_Len]) __THROW {

Re: Expose 'array_length()' macro in

2020-09-22 Thread Florian Weimer via Gcc
* Jonathan Wakely: > I don't see much point in using std::size here. If you're going to > provide the alternative implementation for when std::size isn't > defined, why not just use it always? > > template > #if __cplusplus >= 201103L > constexpr > #endif > inline std::size_t > __array_length(cons

Re: Expose 'array_length()' macro in

2020-09-22 Thread Jonathan Wakely via Gcc
On 22/09/20 11:10 +0200, Alejandro Colomar via Libstdc++ wrote: [[ CC += LKML ]] Thanks for all your input. I learned some C++ :) The following code works for all C and C++ standards: g++ --std={c++98, c++03, c++11, c++14, c++17, c++20} gcc --std={c89, c99, c11, c18, c2x} With `-Wall -Wextra -

Re: [libc-coord] Re: Expose 'array_length()' macro in

2020-09-22 Thread Florian Weimer via Gcc
* Jonathan Wakely: >># define array_length(arr) (std:size(arr)) > > C++ programmers will not accept a macro for this. I think we need a macro for C++98 support because there is no other way to produce constant expression. Note that this intended for C programs compiled in C++ mode. As pointe

Re: Expose 'array_length()' macro in

2020-09-22 Thread Alejandro Colomar via Gcc
[[ CC += LKML ]] Thanks for all your input. I learned some C++ :) The following code works for all C and C++ standards: g++ --std={c++98, c++03, c++11, c++14, c++17, c++20} gcc --std={c89, c99, c11, c18, c2x} With `-Wall -Wextra -Werror -pedantic -Wno-vla -Wno-sizeof-pointer-div`. It doesn't co

Re: Expose 'array_length()' macro in

2020-09-21 Thread Ville Voutilainen via Gcc
On Tue, 22 Sep 2020 at 01:07, Jonathan Wakely via Libstdc++ wrote: > ># define array_length(arr)(std:size(arr)) > > C++ programmers will not accept a macro for this. ..in other words, the C++17 version of it needs to be an inline function that returns std::size of an array, not a macro. All

Re: Expose 'array_length()' macro in

2020-09-21 Thread Jonathan Wakely via Gcc
On 21/09/20 23:52 +0200, Alejandro Colomar via Libstdc++ wrote: I have developed this draft code, the C++ part being based on what you wrote. I am a C programmer, and my C++ is very basic, and I tend to write C-compatible code when I need C++, so I can't really write the C++ part. I tested

Re: Expose 'array_length()' macro in

2020-09-21 Thread Alejandro Colomar via Gcc
I have developed this draft code, the C++ part being based on what you wrote. I am a C programmer, and my C++ is very basic, and I tend to write C-compatible code when I need C++, so I can't really write the C++ part. I tested the code with all C versions (--std= {c89, c99, c11, c18, c2x}),

Re: [libc-coord] Re: Expose 'array_length()' macro in or

2020-09-21 Thread enh via Gcc
Why would C++ programmers need this given https://en.cppreference.com/w/cpp/iterator/size ? On Mon, Sep 21, 2020, 05:54 Alejandro Colomar wrote: > [[ CC += libc-coord at lists.openwall.com ]] > > On 2020-09-21 12:33, Florian Weimer wrote: > > * Alejandro Colomar: > > > >> [[ > >> CC += libc-coor

Re: Expose 'array_length()' macro in or

2020-09-21 Thread Jonathan Wakely via Gcc
On 21/09/20 12:33 +0200, Florian Weimer via Libstdc++ wrote: * Alejandro Colomar: [[ CC += libc-co...@sourceware.org CC += gcc@gcc.gnu.org CC += libstd...@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

Re: Expose 'array_length()' macro in or

2020-09-21 Thread Alejandro Colomar via Gcc
[[ 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-a

Re: Expose 'array_length()' macro in or

2020-09-21 Thread Florian Weimer via Gcc
* Alejandro Colomar: > [[ > CC += libc-co...@sourceware.org > CC += gcc@gcc.gnu.org > CC += libstd...@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

Re: Expose 'array_length()' macro in or

2020-09-21 Thread Alejandro Colomar via Gcc
[[ CC += libc-co...@sourceware.org CC += gcc@gcc.gnu.org CC += libstd...@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.