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


Groups > comp.lang.c > #123210

Re: High level programming in C

From Keith Thompson <kst-u@mib.org>
Newsgroups comp.lang.c
Subject Re: High level programming in C
Date 2017-11-21 12:52 -0800
Organization None to speak of
Message-ID <ln7eujuzfm.fsf@kst-u.example.com> (permalink)
References (8 earlier) <c6b928d9-561f-4597-822b-d759ce14ae92@googlegroups.com> <ov1lqk$uoo$1@dont-email.me> <eae4c1eb-d14c-404f-8730-4b5e2e3208e1@googlegroups.com> <lnfu97v3ag.fsf@kst-u.example.com> <aeebb39c-0f9f-4852-bc2e-f36b085895e2@googlegroups.com>

Show all headers | View raw


supercat@casperkitty.com writes:
> On Tuesday, November 21, 2017 at 1:29:36 PM UTC-6, Keith Thompson wrote:
>> For example, strlen(NULL) has undefined behavior.  The standard
>> *could* have specified the behavior of strlen(NULL) somehow (perhaps
>> returning (size_t)-1 and setting errno, for example), but there's
>> no portable way to check for invalid pointer values other than NULL.
>
> When the Standard was written, there may quite plausibly have been
> implementations where strlen(NULL) would reliably returned zero, and
> some code for such implementations may plausibly have relied upon such
> behavior.  There might also have been implementations where it would
> reliably return (size_t)-1 or some other "special" value, and some
> code for those implementations might plausibly have relied upon that.

I've read an article about, if I recall correctly, the transition
from 68k to SPARC for SunOS (not sure of the details, but it
doesn't really matter).  On the older system, memory location 0 was
readable and happened to contain a zero byte, so strlen(NULL) would
actually return 0, and some code used null pointers to represent
empty strings.  When code was ported to the newer system, a lot of
it broke because memory location 0 was not writable.  (The older
and newer systems both used address 0 to represent the null pointer.)

> If the Standard had required any particular behavior for strlen(NULL),
> that could have made it impossible for some implementations to be made
> conforming without breaking existing code--something the authors of
> the Standard were very keen to avoid.  By contrast, leaving the behavior
> undefined won't break anything as long as implementers use the resulting
> freedom to implement behavior compatible with existing programs.

The standard didn't require any particular behavior for strlen(NULL),
and existing code broke.  That existing code depended on behavior
that was not guaranteed by the language.  The code was fixed.

That's a risk of using a language like C.  Other languages choose
different tradeoffs.

-- 
Keith Thompson (The_Other_Keith) kst-u@mib.org  <http://www.ghoti.net/~kst>
Working, but not speaking, for JetHead Development, Inc.
"We must do something.  This is something.  Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"

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


Thread

High level programming in C jacobnavia <jacob@jacob.remcomp.fr> - 2017-11-20 12:14 +0100
  Re: High level programming in C David Brown <david.brown@hesbynett.no> - 2017-11-20 12:52 +0100
    Re: High level programming in C Robert Wessel <robertwessel2@yahoo.com> - 2017-11-20 06:07 -0600
      Re: High level programming in C David Brown <david.brown@hesbynett.no> - 2017-11-20 13:38 +0100
        Re: High level programming in C jacobnavia <jacob@jacob.remcomp.fr> - 2017-11-20 14:23 +0100
          Re: High level programming in C David Brown <david.brown@hesbynett.no> - 2017-11-20 16:56 +0100
          Re: High level programming in C Spiros Bousbouras <spibou@gmail.com> - 2017-11-20 17:14 +0000
            Re: High level programming in C Spiros Bousbouras <spibou@gmail.com> - 2017-11-20 17:21 +0000
  Re: High level programming in C "Mr. Man-wai Chang" <toylet.toylet@gmail.com> - 2017-11-20 22:45 +0800
  Re: High level programming in C Ian Collins <ian-news@hotmail.com> - 2017-11-21 07:30 +1300
    Re: High level programming in C gazelle@shell.xmission.com (Kenny McCormack) - 2017-11-20 18:32 +0000
      Re: High level programming in C jameskuyper@verizon.net - 2017-11-20 11:05 -0800
        Re: High level programming in C Öö Tiib <ootiib@hot.ee> - 2017-11-20 12:59 -0800
          Re: High level programming in C BGB <cr88192@hotmail.com> - 2017-11-22 10:47 -0600
  Re: High level programming in C fir <profesor.fir@gmail.com> - 2017-11-20 13:17 -0800
    Re: High level programming in C Thiago Adams <thiago.adams@gmail.com> - 2017-11-21 03:26 -0800
      Re: High level programming in C jacobnavia <jacob@jacob.remcomp.fr> - 2017-11-21 14:54 +0100
        Re: High level programming in C scott@slp53.sl.home (Scott Lurndal) - 2017-11-21 14:51 +0000
          Re: High level programming in C David Brown <david.brown@hesbynett.no> - 2017-11-21 16:43 +0100
            Re: High level programming in C Thiago Adams <thiago.adams@gmail.com> - 2017-11-21 07:58 -0800
              Re: High level programming in C jacobnavia <jacob@jacob.remcomp.fr> - 2017-11-21 17:35 +0100
              Re: High level programming in C Spiros Bousbouras <spibou@gmail.com> - 2017-11-21 16:38 +0000
                Re: High level programming in C Thiago Adams <thiago.adams@gmail.com> - 2017-11-21 08:47 -0800
                Re: High level programming in C jacobnavia <jacob@jacob.remcomp.fr> - 2017-11-21 17:55 +0100
                Re: High level programming in C Thiago Adams <thiago.adams@gmail.com> - 2017-11-21 09:06 -0800
                Re: High level programming in C Thiago Adams <thiago.adams@gmail.com> - 2017-11-21 09:13 -0800
                Re: High level programming in C Keith Thompson <kst-u@mib.org> - 2017-11-21 11:29 -0800
                Re: High level programming in C supercat@casperkitty.com - 2017-11-21 11:59 -0800
                Re: High level programming in C Keith Thompson <kst-u@mib.org> - 2017-11-21 12:52 -0800
                Re: High level programming in C supercat@casperkitty.com - 2017-11-21 13:43 -0800
                Re: High level programming in C Keith Thompson <kst-u@mib.org> - 2017-11-21 14:17 -0800
                Re: High level programming in C supercat@casperkitty.com - 2017-11-21 15:00 -0800
                Re: High level programming in C Joe Pfeiffer <pfeiffer@cs.nmsu.edu> - 2017-11-21 15:17 -0700
                Re: High level programming in C supercat@casperkitty.com - 2017-11-21 15:09 -0800
                Re: High level programming in C jacobnavia <jacob@jacob.remcomp.fr> - 2017-11-22 00:55 +0100
                Re: High level programming in C "James R. Kuyper" <jameskuyper@verizon.net> - 2017-11-21 18:58 -0500
                Re: High level programming in C jacobnavia <jacob@jacob.remcomp.fr> - 2017-11-22 01:19 +0100
                Re: High level programming in C Spiros Bousbouras <spibou@gmail.com> - 2017-11-22 01:47 +0000
                Re: High level programming in C Joe Pfeiffer <pfeiffer@cs.nmsu.edu> - 2017-11-21 21:48 -0700
                Re: High level programming in C Spiros Bousbouras <spibou@gmail.com> - 2017-11-22 07:36 +0000
                Re: High level programming in C "James R. Kuyper" <jameskuyper@verizon.net> - 2017-11-22 12:45 -0500
                Re: High level programming in C supercat@casperkitty.com - 2017-11-22 14:00 -0800
                Re: High level programming in C Keith Thompson <kst-u@mib.org> - 2017-11-22 14:25 -0800
                Re: High level programming in C supercat@casperkitty.com - 2017-11-22 15:14 -0800
                Re: High level programming in C Keith Thompson <kst-u@mib.org> - 2017-11-22 16:08 -0800
                Re: High level programming in C supercat@casperkitty.com - 2017-11-23 16:42 -0800
                Re: High level programming in C bartc <bc@freeuk.com> - 2017-11-24 01:37 +0000
                Re: High level programming in C supercat@casperkitty.com - 2017-11-24 14:33 -0800
                Re: High level programming in C Thiago Adams <thiago.adams@gmail.com> - 2017-11-21 16:20 -0800
                Re: High level programming in C David Brown <david.brown@hesbynett.no> - 2017-11-22 10:39 +0100
                Re: High level programming in C Thiago Adams <thiago.adams@gmail.com> - 2017-11-23 02:59 -0800
                Re: High level programming in C David Brown <david.brown@hesbynett.no> - 2017-11-23 12:24 +0100
                Re: High level programming in C Thiago Adams <thiago.adams@gmail.com> - 2017-11-23 04:49 -0800
                Re: High level programming in C scott@slp53.sl.home (Scott Lurndal) - 2017-11-22 15:42 +0000
                Re: High level programming in C Keith Thompson <kst-u@mib.org> - 2017-11-22 08:57 -0800
                Re: High level programming in C Keith Thompson <kst-u@mib.org> - 2017-11-21 09:19 -0800
                Re: High level programming in C Thiago Adams <thiago.adams@gmail.com> - 2017-11-21 09:28 -0800
                Re: High level programming in C supercat@casperkitty.com - 2017-11-21 09:22 -0800
            Re: High level programming in C scott@slp53.sl.home (Scott Lurndal) - 2017-11-21 16:29 +0000
              Re: High level programming in C jacobnavia <jacob@jacob.remcomp.fr> - 2017-11-21 17:43 +0100
          Re: High level programming in C jacobnavia <jacob@jacob.remcomp.fr> - 2017-11-21 17:40 +0100
            Re: High level programming in C Thiago Adams <thiago.adams@gmail.com> - 2017-11-21 08:52 -0800
              Re: High level programming in C Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2017-11-21 09:28 -0800
                Re: High level programming in C Thiago Adams <thiago.adams@gmail.com> - 2017-11-21 09:34 -0800
        Re: High level programming in C Robert Wessel <robertwessel2@yahoo.com> - 2017-11-21 11:37 -0600
          Re: High level programming in C jacobnavia <jacob@jacob.remcomp.fr> - 2017-11-21 20:28 +0100
            Re: High level programming in C Spiros Bousbouras <spibou@gmail.com> - 2017-11-21 19:45 +0000
              Re: High level programming in C "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2017-11-21 11:51 -0800
              Re: High level programming in C jacobnavia <jacob@jacob.remcomp.fr> - 2017-11-21 20:55 +0100
                Re: High level programming in C Spiros Bousbouras <spibou@gmail.com> - 2017-11-21 20:07 +0000
                Re: High level programming in C Ian Collins <ian-news@hotmail.com> - 2017-11-22 09:13 +1300
                Re: High level programming in C scott@slp53.sl.home (Scott Lurndal) - 2017-11-22 15:38 +0000
                Re: High level programming in C Robert Wessel <robertwessel2@yahoo.com> - 2017-11-21 15:17 -0600
                Re: High level programming in C Ian Collins <ian-news@hotmail.com> - 2017-11-22 10:25 +1300
                Re: High level programming in C Robert Wessel <robertwessel2@yahoo.com> - 2017-11-21 15:41 -0600
                Re: High level programming in C David Brown <david.brown@hesbynett.no> - 2017-11-22 11:01 +0100
              Re: High level programming in C antispam@math.uni.wroc.pl - 2017-11-21 20:11 +0000
              Re: High level programming in C David Brown <david.brown@hesbynett.no> - 2017-11-22 10:58 +0100

csiph-web