Hi Paul,

On 5/3/24 2:50 PM, Paul Eggert wrote:
>> The macros for compilers who don't support GCC's builtins are
>> really clever. They don't look like they were too much fun to write
>> though. :)
> 
> Actually they were fun in a twisted sort of way. My secret was to not
> work on them more than 30 minutes at a time (to prevent going
> crazy...).

Haha, nested ternary operators always hurt my brain. It would take me
much longer than you.

Also about this comment in intprops-internal.h:

    /* This include file assumes that signed types are two's complement without
       padding bits; the above macros have undefined behavior otherwise.
       If this is a problem for you, please let us know how to fix it for your 
host.
       This assumption is tested by the intprops-tests module.  */

If you want to check this at compile time I think this should work:

   #if (−1 & 3) == 1
   # error "signed magnitude"
   #elif (-1 & 3) == 2
   # error "one's complement"
   #elif (-1 & 3) == 3
     /* two's complement */
   #endif
   /* or */
   typedef _gl_intprops_verify_twos_complement[(-1 & 3) == 3 ? 1 : -1];

Collin

Reply via email to