Re: __builtin_types_compatible_p or__is_array() alternative for g++?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Thanks a lot, that's exactly what I've been looking for.

On 28 May 2015 at 06:27, Jonathan Wakely <jwakely.gcc@xxxxxxxxx> wrote:
> On 27 May 2015 at 20:29, Eduardo Piombino wrote:
>> Hi.
>>
>> I'm currently using __builtin_types_compatible_p basically for
>> determining if the passed value is an array in the following manner:
>>
>> #define __same_type(a, b) __builtin_types_compatible_p(typeof(a), typeof(b))
>> #define __is_array(a) (__same_type((a), &(a)[0]) == 0)
>>
>> This way the __is_array() tells me if im dealing with an array or a
>> bare pointer:
>>
>> char dest[10];
>> char * p;
>>
>> __is_array(dest) would evaluate to 1, while __is_array(p) would
>> evaluate to 0, allowing me to raise a warning or an assert at compile
>> time.
>
> You don't need any bultins for C++:
>
> static_assert( std::is_array<decltype(dest)>::value, "dest is an array" );
> static_assert( !std::is_array<decltype(p)>::value, "p is not an array" );




[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux