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,449 of 243,242   
   David Brown to Waldek Hebisch   
   Re: bugprone-switch-missing-default-case   
   24 Oct 25 09:53:26   
   
   From: david.brown@hesbynett.no   
      
   On 24/10/2025 01:23, Waldek Hebisch wrote:   
   > Thiago Adams  wrote:   
   >> On 10/23/2025 12:06 PM, David Brown wrote:   
   >>> On 23/10/2025 13:03, Thiago Adams wrote:   
      
   >>   
   >> Then when adding a new enumerator the programmer will have to review   
   >> this code and update to 21 if it is not used, or handle it in a new case.   
   >   
   > This helps catch some switches that need attention, but will miss   
   > situations where you need to change handling of some existing code,   
   > more precisely, when you need to remove case from some switches and   
   > add it to different ones.   
   >   
   > In similar cases I usually depend on a different approach: I am   
   > writing my types in a way that can be found by textual searches.   
   > If there is any change to usage pattern I search for all uses   
   > of given type (I may also wrap enum inside otherwise useless   
   > struct to make sure that all uses need declaration).   
      
   Since you mention "textual searches", one technique that can sometimes   
   be helpful when you change a definition and want to be sure that you   
   have changed or checked all uses is to change the names in the   
   declaration.  While we have been using "enum E { A, B, C };" in these   
   posts, real code typically has longer names - perhaps "enum run_states",   
   or whatever, with either a prefix or a postfix to the enumeration type   
   and the enumerators.  If you change that in your declaration, such as by   
   adding an X somewhere, you are guaranteed compile-time errors until you   
   have gone through all the uses in the code and added the X as you   
   checked the use-cases and changed or added as appropriate.  Once   
   everything is complete, a big search-and-replace can remove the X's.   
      
   --- 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