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


Groups > comp.lang.c > #398058

Re: Small challenge: sort names

From cross@spitfire.i.gajendra.net (Dan Cross)
Newsgroups comp.lang.c
Subject Re: Small challenge: sort names
Date 2026-04-28 13:27 +0000
Organization PANIX Public Access Internet and UNIX, NYC
Message-ID <10sqck5$elp$1@reader1.panix.com> (permalink)
References <10r4h6o$396qn$1@dont-email.me> <10sof6k$2l43i$1@kst.eternal-september.org> <10sohpc$444$1@reader1.panix.com> <10spkg2$2uc64$1@dont-email.me>

Show all headers | View raw


In article <10spkg2$2uc64$1@dont-email.me>,
David Brown  <david.brown@hesbynett.no> wrote:
>On 27/04/2026 22:43, Dan Cross wrote:
>> In article <10sof6k$2l43i$1@kst.eternal-september.org>,
>> Keith Thompson  <Keith.S.Thompson+u@gmail.com> wrote:
>>> "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> writes:
>>>> On 4/27/2026 12:42 PM, Chris M. Thomasson wrote:
>>> [...]
>>>>> Fwiw, I only use '\0' for the null terminator in strings, not for
>>>>> pointers...
>>>
>>> I'm not sure why that's worth mentioning.  The only reason I can
>>> think of to use '\0' for pointers is deliberate obfuscation, or
>>> *maybe* testing how a compiler handles it.
>> 
>> Some time ago, a rather famous production outage at Google was
>> the result of something very similar.  The author wrote,
>> 
>> 	ptr->some_bool = false;
>> 
>> where what was meant was,
>> 
>> 	*ptr->some_bool = false;
>> 
>> Here, `some_bool` was `bool *some_bool`.  Perfectly legal, of
>> course: `false` was just a macro expanding to the integer
>> constant 0, which in pointer context is a null pointer constant,
>> thus setting `some_bool` to the null pointer.  But clearly what
>> was meant was to assign false to the actual boolean.  Oops.
>> 
>> At the time, the compiler (gcc) did not emit a diagnostic for
>> this, but `clang` did.  The build system was quickly changed to
>> invoke both; showing combined diagnostics from both compilers,
>> but keeping only the object file emitted by gcc (as I understand
>> it, Google has since switched to using `clang` as the default
>> compiler in its monorepo).
>> 
>> This, and similar incidents, are one reason I greatly prefer
>> domain-specific constructs (e.g, '\0' for character data instead
>> of plain ol' 0) and explicit comparisons (`if (ptr != NULL)` vs
>> `if (ptr)`).  Over time and at large enough scale, these things
>> really do start to matter.
>
>Unfortunately in this case, "false" /is/ the domain-specific construct 
>for setting the boolean to false (rather than using, say, 0).

Indeed it is!  But not for pointers.  Nothing prevents a
compiler frontend from emiting a warning saying, "you are
assigning false to a pointer to bool, not the bool; did you
forget a `*`?"  Indeed, `clang` did that, but `gcc` (at the
time; this was well over a decade ago now) did not.

And, of course, a human reviewer looking at that _should_ say,
"wait, assigning `false` to a pointer doesn't seem right...."
whereas using `0` is ambiguous.  (All production code at Google
is reviewed, but in this case, the reviewer simply missed the
bug.)

>I fully 
>agree with you on the principle, however.

I'm tracking.  Just clarifying what I meant above.

>And unfortunately, C has a number of implicit conversions that can be 
>inappropriate in real code, such as this one.  I don't think it is 
>possible at this stage to change this.  (C++, I believe, disallows this 
>particular code - but the rules for conversion to and from bool in C++ 
>are very complicated and not easily transferable to C.)  Compiler 
>warnings, despite the code being valid C, are the best we can hope for 
>here.  (It's a shame gcc doesn't warn on that one - clang and gcc each 
>have a few unique warnings, so using both for static error checking is 
>not a bad idea.)

GCC may well warn on it now; this incident (which made the press
at the time) was a very long time ago now.

>Even in C++, many people find the implicit bool conversions too broad, 
>and prefer to use a "strong bool" type.

I would not classify C++ as a strongly-typed language, in large
part because of the implicit conversions it inherited from C.

In Rust, for example, there are no such conversions, and the
language enforces that conditionals evaluate an expression
resulting in an explicit `bool`.  Hence, in that language, one
cannot write `let foo = 0u8; if foo { ... }` because `foo` is
not a `bool`, despite having the same value and representation
as `false`.

	- Dan C.

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


Thread

Small challenge: sort names DFS <nospam@dfs.com> - 2026-04-07 23:14 -0400
  Re: Small challenge: sort names Janis Papanagnou <janis_papanagnou+ng@hotmail.com> - 2026-04-08 10:22 +0200
    Re: Small challenge: sort names DFS <nospam@dfs.com> - 2026-04-08 12:25 -0400
      Re: Small challenge: sort names Bart <bc@freeuk.com> - 2026-04-08 18:57 +0100
        Re: Small challenge: sort names scott@slp53.sl.home (Scott Lurndal) - 2026-04-08 21:04 +0000
          Re: Small challenge: sort names Michael S <already5chosen@yahoo.com> - 2026-04-09 00:10 +0300
            Re: Small challenge: sort names scott@slp53.sl.home (Scott Lurndal) - 2026-04-08 23:35 +0000
              Re: Small challenge: sort names Michael S <already5chosen@yahoo.com> - 2026-04-09 02:59 +0300
                Re: Small challenge: sort names James Kuyper <jameskuyper@alumni.caltech.edu> - 2026-04-09 06:29 -0400
                Re: Small challenge: sort names cross@spitfire.i.gajendra.net (Dan Cross) - 2026-04-09 15:15 +0000
                Re: Small challenge: sort names Tim Rentsch <tr.17687@z991.linuxsc.com> - 2026-04-11 08:49 -0700
                Re: Small challenge: sort names cross@spitfire.i.gajendra.net (Dan Cross) - 2026-04-11 19:59 +0000
                Re: Small challenge: sort names Bonita Montero <Bonita.Montero@gmail.com> - 2026-04-16 18:50 +0200
                Re: Small challenge: sort names cross@spitfire.i.gajendra.net (Dan Cross) - 2026-04-16 19:54 +0000
                Re: Small challenge: sort names Bonita Montero <Bonita.Montero@gmail.com> - 2026-04-17 16:22 +0200
              Re: Small challenge: sort names Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2026-04-08 17:27 -0700
              Re: Small challenge: sort names Tim Rentsch <tr.17687@z991.linuxsc.com> - 2026-04-08 22:14 -0700
                Re: Small challenge: sort names Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2026-04-09 02:19 -0700
                Re: Small challenge: sort names scott@slp53.sl.home (Scott Lurndal) - 2026-04-09 15:06 +0000
                Re: Small challenge: sort names Tim Rentsch <tr.17687@z991.linuxsc.com> - 2026-04-12 06:35 -0700
                Re: Small challenge: sort names scott@slp53.sl.home (Scott Lurndal) - 2026-04-12 14:51 +0000
                Re: Small challenge: sort names Tim Rentsch <tr.17687@z991.linuxsc.com> - 2026-04-13 06:31 -0700
                Re: Small challenge: sort names Tim Rentsch <tr.17687@z991.linuxsc.com> - 2026-04-12 06:48 -0700
                Re: Small challenge: sort names Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2026-04-12 16:15 -0700
                Re: Small challenge: sort names Tim Rentsch <tr.17687@z991.linuxsc.com> - 2026-04-25 13:31 -0700
                Re: Small challenge: sort names Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2026-04-25 15:12 -0700
                Re: Small challenge: sort names Janis Papanagnou <janis_papanagnou+ng@hotmail.com> - 2026-04-26 04:13 +0200
                Re: Small challenge: sort names Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2026-04-25 19:50 -0700
                Re: Small challenge: sort names Janis Papanagnou <janis_papanagnou+ng@hotmail.com> - 2026-04-26 05:28 +0200
                Re: Small challenge: sort names David Brown <david.brown@hesbynett.no> - 2026-04-26 12:08 +0200
                Re: Small challenge: sort names Janis Papanagnou <janis_papanagnou+ng@hotmail.com> - 2026-04-26 18:16 +0200
                Re: Small challenge: sort names David Brown <david.brown@hesbynett.no> - 2026-04-26 19:37 +0200
                Re: Small challenge: sort names Janis Papanagnou <janis_papanagnou+ng@hotmail.com> - 2026-04-27 02:17 +0200
                Re: Small challenge: sort names David Brown <david.brown@hesbynett.no> - 2026-04-27 09:19 +0200
                Re: Small challenge: sort names scott@slp53.sl.home (Scott Lurndal) - 2026-04-26 17:47 +0000
                Re: Small challenge: sort names Janis Papanagnou <janis_papanagnou+ng@hotmail.com> - 2026-04-27 02:33 +0200
                Re: Small challenge: sort names David Brown <david.brown@hesbynett.no> - 2026-04-27 09:34 +0200
                Re: Small challenge: sort names Janis Papanagnou <janis_papanagnou+ng@hotmail.com> - 2026-04-27 12:35 +0200
                Re: Small challenge: sort names Bart <bc@freeuk.com> - 2026-04-27 13:28 +0100
                Re: Small challenge: sort names Janis Papanagnou <janis_papanagnou+ng@hotmail.com> - 2026-04-27 17:02 +0200
                Re: Small challenge: sort names Janis Papanagnou <janis_papanagnou+ng@hotmail.com> - 2026-04-27 17:36 +0200
                Re: Small challenge: sort names scott@slp53.sl.home (Scott Lurndal) - 2026-04-27 16:18 +0000
                Re: Small challenge: sort names Michael S <already5chosen@yahoo.com> - 2026-04-27 11:42 +0300
                Re: Small challenge: sort names scott@slp53.sl.home (Scott Lurndal) - 2026-04-27 16:27 +0000
                Assembler verb choice (Was: Small challenge: sort names) gazelle@shell.xmission.com (Kenny McCormack) - 2026-04-28 12:59 +0000
                Re: Assembler verb choice (Was: Small challenge: sort names) Janis Papanagnou <janis_papanagnou+ng@hotmail.com> - 2026-04-28 16:26 +0200
                Re: Small challenge: sort names "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2026-04-27 12:45 -0700
                Re: Small challenge: sort names "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2026-04-27 12:42 -0700
                Re: Small challenge: sort names "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2026-04-27 12:43 -0700
                Re: Small challenge: sort names Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2026-04-27 12:59 -0700
                Re: Small challenge: sort names "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2026-04-27 13:26 -0700
                Re: Small challenge: sort names cross@spitfire.i.gajendra.net (Dan Cross) - 2026-04-27 20:43 +0000
                Re: Small challenge: sort names "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2026-04-27 17:30 -0700
                Re: Small challenge: sort names Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2026-04-27 19:15 -0700
                Re: Small challenge: sort names gazelle@shell.xmission.com (Kenny McCormack) - 2026-04-28 12:01 +0000
                Re: Small challenge: sort names David Brown <david.brown@hesbynett.no> - 2026-04-28 08:35 +0200
                Re: Small challenge: sort names cross@spitfire.i.gajendra.net (Dan Cross) - 2026-04-28 13:27 +0000
                Re: Small challenge: sort names David Brown <david.brown@hesbynett.no> - 2026-04-28 15:59 +0200
                Re: Small challenge: sort names Janis Papanagnou <janis_papanagnou+ng@hotmail.com> - 2026-04-28 16:49 +0200
                Re: Small challenge: sort names David Brown <david.brown@hesbynett.no> - 2026-04-28 17:25 +0200
                Re: Small challenge: sort names Janis Papanagnou <janis_papanagnou+ng@hotmail.com> - 2026-04-28 23:46 +0200
                Re: Small challenge: sort names cross@spitfire.i.gajendra.net (Dan Cross) - 2026-04-28 18:12 +0000
                Re: Small challenge: sort names David Brown <david.brown@hesbynett.no> - 2026-04-28 20:28 +0200
                Re: Small challenge: sort names vallor <vallor@vallor.earth> - 2026-04-28 13:45 +0000
          Re: Small challenge: sort names Janis Papanagnou <janis_papanagnou+ng@hotmail.com> - 2026-04-11 08:44 +0200
        Re: Small challenge: sort names DFS <nospam@dfs.com> - 2026-04-08 17:13 -0400
          Re: Small challenge: sort names Janis Papanagnou <janis_papanagnou+ng@hotmail.com> - 2026-04-11 08:59 +0200
            Re: Small challenge: sort names Janis Papanagnou <janis_papanagnou+ng@hotmail.com> - 2026-04-11 09:34 +0200
      Re: Small challenge: sort names Janis Papanagnou <janis_papanagnou+ng@hotmail.com> - 2026-04-11 08:31 +0200
      Re: Small challenge: sort names vallor <vallor@vallor.earth> - 2026-04-28 14:19 +0000
    Re: Small challenge: sort names BGB <cr88192@gmail.com> - 2026-04-12 13:08 -0500
    What is the point of anything? (Was: Small challenge: sort names) gazelle@shell.xmission.com (Kenny McCormack) - 2026-04-17 20:44 +0000
  Re: Small challenge: sort names Tim Rentsch <tr.17687@z991.linuxsc.com> - 2026-04-08 18:46 -0700
  Re: Small challenge: sort names Sort <Sort@invalid.invalid> - 2026-04-11 19:15 +0100
  Re: Small challenge: sort names Bonita Montero <Bonita.Montero@gmail.com> - 2026-04-16 18:24 +0200
    Re: Small challenge: sort names Bart <bc@freeuk.com> - 2026-04-16 18:38 +0100
      Re: Small challenge: sort names Bonita Montero <Bonita.Montero@gmail.com> - 2026-04-16 19:43 +0200
    Re: Small challenge: sort names Bart <bc@freeuk.com> - 2026-04-18 11:22 +0100
      Re: Small challenge: sort names Bonita Montero <Bonita.Montero@gmail.com> - 2026-04-18 17:48 +0200
        Re: Small challenge: sort names Bonita Montero <Bonita.Montero@gmail.com> - 2026-04-19 08:44 +0200
    Re: Small challenge: sort names DFS <nospam@dfs.com> - 2026-04-22 05:33 -0400
      Re: Small challenge: sort names Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2026-04-22 03:16 -0700
        Re: Small challenge: sort names DFS <nospam@dfs.com> - 2026-04-22 07:35 -0400
          Re: Small challenge: sort names Tim Rentsch <tr.17687@z991.linuxsc.com> - 2026-04-23 08:11 -0700
            Re: Small challenge: sort names Bonita Montero <Bonita.Montero@gmail.com> - 2026-04-23 20:14 +0200
              Re: Small challenge: sort names gazelle@shell.xmission.com (Kenny McCormack) - 2026-04-23 18:30 +0000
        Re: Small challenge: sort names gazelle@shell.xmission.com (Kenny McCormack) - 2026-04-23 17:19 +0000
      Re: Small challenge: sort names Janis Papanagnou <janis_papanagnou+ng@hotmail.com> - 2026-04-22 14:11 +0200
        Re: Small challenge: sort names James Kuyper <jameskuyper@alumni.caltech.edu> - 2026-04-22 21:27 -0400
          [OT][meta] Gender (was Re: Small challenge: sort names) Janis Papanagnou <janis_papanagnou+ng@hotmail.com> - 2026-04-23 15:51 +0200
            Re: [OT][meta] Gender (was Re: Small challenge: sort names) scott@slp53.sl.home (Scott Lurndal) - 2026-04-23 14:45 +0000
              Re: [OT][meta] Gender (was Re: Small challenge: sort names) Janis Papanagnou <janis_papanagnou+ng@hotmail.com> - 2026-04-23 17:03 +0200
              Re: [OT][meta] Gender (was Re: Small challenge: sort names) DFS <nospam@dfs.com> - 2026-04-23 20:31 -0400
                Re: [OT][meta] Gender (was Re: Small challenge: sort names) Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2026-04-23 18:43 -0700
                Re: [OT][meta] Gender (was Re: Small challenge: sort names) gazelle@shell.xmission.com (Kenny McCormack) - 2026-04-24 16:58 +0000
                Re: [OT][meta] Gender (was Re: Small challenge: sort names) Jan van den Broek <balglaas@dds.nl> - 2026-04-24 06:57 +0000
                Re: [OT][meta] Gender (was Re: Small challenge: sort names) Bonita Montero <Bonita.Montero@gmail.com> - 2026-04-24 10:10 +0200
                Re: [OT][meta] Gender (was Re: Small challenge: sort names) David Brown <david.brown@hesbynett.no> - 2026-04-24 12:52 +0200
            Re: [OT][meta] Gender (was Re: Small challenge: sort names) Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2026-04-23 16:36 -0700
              Re: [OT][meta] Gender (was Re: Small challenge: sort names) Janis Papanagnou <janis_papanagnou+ng@hotmail.com> - 2026-04-24 03:01 +0200
                Re: [OT][meta] Gender (was Re: Small challenge: sort names) Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2026-04-23 18:50 -0700
                Re: [OT][meta] Gender (was Re: Small challenge: sort names) "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2026-04-24 20:35 -0700
            Re: [OT][meta] Gender (was Re: Small challenge: sort names) Michael S <already5chosen@yahoo.com> - 2026-04-24 14:20 +0300
              Re: [OT][meta] Gender (was Re: Small challenge: sort names) Janis Papanagnou <janis_papanagnou+ng@hotmail.com> - 2026-04-24 14:32 +0200
      Re: Small challenge: sort names Bonita Montero <Bonita.Montero@gmail.com> - 2026-04-23 20:10 +0200
        Re: Small challenge: sort names DFS <nospam@dfs.com> - 2026-04-25 10:26 -0400
          Re: Small challenge: sort names Bonita Montero <Bonita.Montero@gmail.com> - 2026-04-26 13:01 +0200
  Re: Small challenge: sort names Rosario19 <Ros@invalid.invalid> - 2026-04-18 11:16 +0200
    Re: Small challenge: sort names DFS <nospam@dfs.com> - 2026-04-18 08:11 -0400
      Re: Small challenge: sort names Bart <bc@freeuk.com> - 2026-04-18 14:03 +0100
    Re: Small challenge: sort names Rosario19 <Ros@invalid.invalid> - 2026-04-20 21:20 +0200
      Re: Small challenge: sort names DFS <nospam@dfs.com> - 2026-04-20 16:43 -0400
        Re: Small challenge: sort names Rosario19 <Ros@invalid.invalid> - 2026-04-21 05:09 +0200
          Re: Small challenge: sort names DFS <nospam@dfs.com> - 2026-04-21 08:46 -0400
            Re: Small challenge: sort names Bart <bc@freeuk.com> - 2026-04-21 16:08 +0100
              Re: Small challenge: sort names DFS <nospam@dfs.com> - 2026-04-21 11:33 -0400
                Re: Small challenge: sort names Bart <bc@freeuk.com> - 2026-04-21 18:25 +0100
                Re: Small challenge: sort names scott@slp53.sl.home (Scott Lurndal) - 2026-04-21 17:38 +0000
                Re: Small challenge: sort names Michael S <already5chosen@yahoo.com> - 2026-04-21 20:50 +0300
                Re: Small challenge: sort names scott@slp53.sl.home (Scott Lurndal) - 2026-04-21 18:22 +0000
                Re: Small challenge: sort names Janis Papanagnou <janis_papanagnou+ng@hotmail.com> - 2026-04-22 03:48 +0200
                Re: Small challenge: sort names David Brown <david.brown@hesbynett.no> - 2026-04-22 09:18 +0200
                Re: Small challenge: sort names Michael S <already5chosen@yahoo.com> - 2026-04-22 13:22 +0300
                Re: Small challenge: sort names David Brown <david.brown@hesbynett.no> - 2026-04-22 12:38 +0200
                Re: Small challenge: sort names Michael S <already5chosen@yahoo.com> - 2026-04-22 13:58 +0300
                Re: Small challenge: sort names David Brown <david.brown@hesbynett.no> - 2026-04-22 13:13 +0200
                Re: Small challenge: sort names Janis Papanagnou <janis_papanagnou+ng@hotmail.com> - 2026-04-22 14:53 +0200
                Re: Small challenge: sort names DFS <nospam@dfs.com> - 2026-04-21 16:31 -0400
                Re: Small challenge: sort names Bart <bc@freeuk.com> - 2026-04-21 23:04 +0100
      Re: Small challenge: sort names Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2026-04-20 14:16 -0700
        An audience of one (Was: Small challenge: sort names) gazelle@shell.xmission.com (Kenny McCormack) - 2026-04-21 13:00 +0000
          Re: An audience of one (Was: Small challenge: sort names) "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2026-04-21 12:21 -0700
    Re: Small challenge: sort names Rosario19 <Ros@invalid.invalid> - 2026-04-21 05:00 +0200
      Re: Small challenge: sort names Rosario19 <Ros@invalid.invalid> - 2026-04-21 05:06 +0200
  Re: Small challenge: sort names gggggggggggunit <gunitinug@50cent.com> - 2026-04-18 10:19 +0000
    [OT] Shell approach to Re: Small challenge: sort names Janis Papanagnou <janis_papanagnou+ng@hotmail.com> - 2026-04-19 09:35 +0200
      Re: [OT] Shell approach to Re: Small challenge: sort names gazelle@shell.xmission.com (Kenny McCormack) - 2026-04-19 14:18 +0000
        Re: [OT] Shell approach to Re: Small challenge: sort names cross@spitfire.i.gajendra.net (Dan Cross) - 2026-04-19 19:32 +0000
          Re: [OT] Shell approach to Re: Small challenge: sort names Janis Papanagnou <janis_papanagnou+ng@hotmail.com> - 2026-04-22 03:34 +0200
  Re: Small challenge: sort names Bonita Montero <Bonita.Montero@gmail.com> - 2026-04-28 06:53 +0200
    Re: Small challenge: sort names gazelle@shell.xmission.com (Kenny McCormack) - 2026-04-28 13:01 +0000

csiph-web