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,420 of 243,242    |
|    David Brown to Janis Papanagnou    |
|    Re: bugprone-switch-missing-default-case    |
|    23 Oct 25 09:30:46    |
      From: david.brown@hesbynett.no              On 23/10/2025 04:54, Janis Papanagnou wrote:       > On 22.10.2025 17:23, David Brown wrote:       >> On 22/10/2025 16:05, Janis Papanagnou wrote:              >> But it does nothing to help say how it happened to run.       >       > ??? - The example scenario will run. Just may have erroneous results       > when triggering the case that isn't handled. With diagnostic records       > you can quickly identify and fix it (usually in one of the QA test       > cycles before you deliver the software).       >              There may have been a misunderstanding here about what your various       "..." lines before the switch statement did. I understood them to be       checking the input data for validity, in which case the default case is       unnecessary and will not be run. But if the switch itself is checking       the input data, then the default case is an integral part of that check.        It's not an unnecessary or extra default added by habit, it's just       normal usage.              >> A printf call that never runs is not free -       >> it costs in many different ways, and should not be there unless it is       >> worth those costs.       >       > (You're obviously a better discussion candidate for folks who count       > bytes and microseconds, say, like bart. - The "costs" that matters       > much more in professional software development are quality and time.)       >              As a professional software developer, costs matter - different kinds of       costs, scaled differently in different situations. Yes, developer costs       matter. So do run-time costs. If developer costs are the only thing       that matters and run-time costs do not, then why are you programming in       C? There can be a number of good reasons for choosing C over, say,       Python, but run-time efficiency for at least part of the code is very       often a major reason.              I work mainly on small-system embedded devices. A printf is a very       expensive operation in many ways. I'll use it if it is the right thing       to use, and not if is inappropriate. For some of my systems, being       slap-dash about printf's and the like means the code won't fit in the       microcontroller's flash, and we need a new hardware design (at very       significant developer cost). Not long ago I wrote some code that had to       run in less than a tenth of a microsecond - adding an extra printf, even       if it was never called, would have added overhead to the function which       would have exceeded the timing requirements. Timing failures here would       mean shoot-through of power transistors and blowing the boards.              Premature optimisation is the root of all evil, but premature       pessimisation is not good either. You have to know when code needs to       be efficient, and pick different balances between developer costs and       run-time costs according to the situation.              --- 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