Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #394675

Re: bugprone-switch-missing-default-case

From David Brown <david.brown@hesbynett.no>
Newsgroups comp.lang.c
Subject Re: bugprone-switch-missing-default-case
Date 2025-10-23 09:30 +0200
Organization A noiseless patient Spider
Message-ID <10dclj6$1dnn6$3@dont-email.me> (permalink)
References (2 earlier) <10dag3d$jkju$1@dont-email.me> <10damv3$ku01$1@dont-email.me> <10daob9$m3em$1@dont-email.me> <10dasso$nfjr$1@dont-email.me> <10dc5cr$163j9$1@dont-email.me>

Show all headers | View raw


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.


Back to comp.lang.c | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

bugprone-switch-missing-default-case pozz <pozzugno@gmail.com> - 2025-10-22 10:56 +0200
  Re: bugprone-switch-missing-default-case Janis Papanagnou <janis_papanagnou+ng@hotmail.com> - 2025-10-22 11:32 +0200
    Re: bugprone-switch-missing-default-case Richard Harnden <richard.nospam@gmail.invalid> - 2025-10-22 12:44 +0100
      Re: bugprone-switch-missing-default-case Thiago Adams <thiago.adams@gmail.com> - 2025-10-22 10:05 -0300
        Re: bugprone-switch-missing-default-case Kaz Kylheku <643-408-1753@kylheku.com> - 2025-10-22 18:22 +0000
          Re: bugprone-switch-missing-default-case David Brown <david.brown@hesbynett.no> - 2025-10-23 09:12 +0200
            Re: bugprone-switch-missing-default-case Thiago Adams <thiago.adams@gmail.com> - 2025-10-23 08:03 -0300
              Re: bugprone-switch-missing-default-case David Brown <david.brown@hesbynett.no> - 2025-10-23 17:06 +0200
                Re: bugprone-switch-missing-default-case Thiago Adams <thiago.adams@gmail.com> - 2025-10-23 13:15 -0300
                Re: bugprone-switch-missing-default-case bart <bc@freeuk.com> - 2025-10-23 17:46 +0100
                Re: bugprone-switch-missing-default-case Thiago Adams <thiago.adams@gmail.com> - 2025-10-23 14:12 -0300
                Re: bugprone-switch-missing-default-case David Brown <david.brown@hesbynett.no> - 2025-10-23 22:40 +0200
                Re: bugprone-switch-missing-default-case scott@slp53.sl.home (Scott Lurndal) - 2025-10-23 20:51 +0000
                Re: bugprone-switch-missing-default-case Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2025-10-23 16:21 -0700
                Re: bugprone-switch-missing-default-case David Brown <david.brown@hesbynett.no> - 2025-10-24 08:59 +0200
                Re: bugprone-switch-missing-default-case scott@slp53.sl.home (Scott Lurndal) - 2025-10-24 15:51 +0000
                Re: bugprone-switch-missing-default-case tTh <tth@none.invalid> - 2025-10-23 23:57 +0200
                Re: bugprone-switch-missing-default-case David Brown <david.brown@hesbynett.no> - 2025-10-24 09:22 +0200
                Re: bugprone-switch-missing-default-case antispam@fricas.org (Waldek Hebisch) - 2025-10-23 23:23 +0000
                Re: bugprone-switch-missing-default-case David Brown <david.brown@hesbynett.no> - 2025-10-24 09:53 +0200
      Re: bugprone-switch-missing-default-case David Brown <david.brown@hesbynett.no> - 2025-10-22 15:41 +0200
        Re: bugprone-switch-missing-default-case Janis Papanagnou <janis_papanagnou+ng@hotmail.com> - 2025-10-22 16:05 +0200
          Re: bugprone-switch-missing-default-case David Brown <david.brown@hesbynett.no> - 2025-10-22 17:23 +0200
            Re: bugprone-switch-missing-default-case Janis Papanagnou <janis_papanagnou+ng@hotmail.com> - 2025-10-23 04:54 +0200
              Re: bugprone-switch-missing-default-case David Brown <david.brown@hesbynett.no> - 2025-10-23 09:30 +0200
            Re: bugprone-switch-missing-default-case antispam@fricas.org (Waldek Hebisch) - 2025-10-23 22:40 +0000
        Re: bugprone-switch-missing-default-case Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2025-10-22 12:41 -0700
          Re: bugprone-switch-missing-default-case pozz <pozzugno@gmail.com> - 2025-10-23 08:47 +0200
            Re: bugprone-switch-missing-default-case Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2025-10-23 16:17 -0700
              Re: bugprone-switch-missing-default-case Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2025-10-23 19:13 -0700
          Re: bugprone-switch-missing-default-case David Brown <david.brown@hesbynett.no> - 2025-10-23 10:44 +0200
      Re: bugprone-switch-missing-default-case Janis Papanagnou <janis_papanagnou+ng@hotmail.com> - 2025-10-22 15:56 +0200
        Re: bugprone-switch-missing-default-case David Brown <david.brown@hesbynett.no> - 2025-10-22 17:25 +0200
          Re: bugprone-switch-missing-default-case Janis Papanagnou <janis_papanagnou+ng@hotmail.com> - 2025-10-23 04:39 +0200
            Re: bugprone-switch-missing-default-case David Brown <david.brown@hesbynett.no> - 2025-10-23 09:08 +0200
          Re: bugprone-switch-missing-default-case Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2025-10-23 16:31 -0700
            Re: bugprone-switch-missing-default-case David Brown <david.brown@hesbynett.no> - 2025-10-24 10:09 +0200
  Re: bugprone-switch-missing-default-case Kaz Kylheku <643-408-1753@kylheku.com> - 2025-10-22 18:13 +0000

csiph-web