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 241,348 of 243,242   
   Michael S to pozz   
   Re: signed vs unsigned and gcc -Wsign-co   
   20 Oct 25 19:43:37   
   
   From: already5chosen@yahoo.com   
      
   On Mon, 20 Oct 2025 17:03:58 +0200   
   pozz  wrote:   
      
   > After many years programming in C language, I'm always unsure if it   
   > is safer to use signed int or unsigned int.   
   >   
   > Of course there are situations where signed or unsigned is clearly   
   > better. For example, if the values could assume negative values,   
   > signed int is the only solution. If you are manipulating single bits   
   > (&, |, ^, <<, >>), unsigned ints are your friends.   
   >   
   > What about other situations? For example, what do you use for the "i"   
   > loop variable?   
   >   
      
   I'd just point out that small negative numbers are FAR more common than   
   numbers in range [2**31..2**32-1].   
   Now, make your own conclusion.   
      
      
   > I recently activated gcc -Wsign-conversion option on a codebase and   
   > received a lot of warnings. I started to fix them, usually   
   > expliciting casting. Is it the way or is it better to avoid the   
   > warning from the beginning, choosing the right signed or unsigned   
   > type?   
   >   
   >   
      
   --- 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