home bbs files messages ]

Forums before death by AOL, social media and spammers... "We can't have nice things"

   comp.lang.c      Meh, in C you gotta define EVERYTHING      243,242 messages   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]

   Message 242,302 of 243,242   
   bart to Keith Thompson   
   Re: _BitInt(N)   
   01 Dec 25 22:01:49   
   
   From: bc@freeuk.com   
      
   On 01/12/2025 20:34, Keith Thompson wrote:   
   > bart  writes:   
      
   >> The following table for example shows the rules for mixed sign   
   >> arithmetic: S means the result (32 or 64 bits) has signed type, and u   
   >> means it is unsigned:   
   >>   
   >>         u8  u16 u32 u64  i8  i16 i32 i64   
   >>   
   >>     u8   S   S   u   u    S   S   S   S   
   >>    u16   S   S   u   u    S   S   S   S   
   >>    u32   u   u   u   u    u   u   u   S   
   >>    u64   u   u   u   u    u   u   u   u   
   >>   
   >>     i8   S   S   u   u    S   S   S   S   
   >>    i16   S   S   u   u    S   S   S   S   
   >>    i32   S   S   u   u    S   S   S   S   
   >>    i64   S   S   S   u    S   S   S   S   
   >>   
   >> But of course, every C programmer knows this and doesn't need such a chart!   
   >   
   > I'm not going to take the time to confirm that your chart is correct.   
   > It assumes that int is 32 bits; an implementation with 16-bit or   
   > 64-bit int would require a different chart.   
   >   
   > But the fact that you were able to generate the chart means that   
   > *you already understand the rules*.  You just choose to express   
   > those rules in a way that's more confusing.   
      
   That doesn't follow; the chart was created by a C program (by submitting   
   64 combinations of typed variables (eg. issigned(x * y)) to the macro   
   below, compiled with gcc.   
      
   My own C compiler produces a quite different chart, but I'm not   
   interested at this point in rewriting the front-end, considering the   
   many other ways it doesn't conform.   
      
   Fortunately this doesn't seem to affect too many things.   
      
   As example, the above says that i8 * u32 (or u32 * i8) is unsigned; my   
   chart says it's signed. The difference can be demonstrated here:   
      
        signed char a = -2;   
        unsigned int b = 13;   
      
        printf("%f\n", (double)(a*b));   
      
   The output is:   
      
      gcc  4294967270.000000   
      bcc         -26.000000   
      
   I don't know about you, but to me, my result looks a lot more intuitive!   
   So I also didn't /want/ to change it to something I didn't agree with.   
      
      
   -------------------------------------------------   
      
     #define issigned(x) _Generic((x),\   
        int8_t: "S",\   
        int16_t: "S",\   
        int32_t: "S",\   
        int64_t: "S",\   
        uint8_t: "u",\   
        uint16_t: "u",\   
        uint32_t: "u",\   
        uint64_t: "u",\   
        default: "other")   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]


(c) 1994,  bbs@darkrealms.ca