Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c > #123339
| From | Keith Thompson <kst-u@mib.org> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: High level programming in C |
| Date | 2017-11-22 14:25 -0800 |
| Organization | None to speak of |
| Message-ID | <lnr2sqrlvs.fsf@kst-u.example.com> (permalink) |
| References | (14 earlier) <1bmv3fz37a.fsf@pfeifferfamily.net> <c78bb494-feb3-9823-1378-a468d2a8e72f@verizon.net> <1bfu96zzof.fsf@pfeifferfamily.net> <7bddbd1b-a738-73e5-cd43-b7d65e4e4310@verizon.net> <ddc0caeb-1f8c-43b4-83d6-9fd0d990f7b1@googlegroups.com> |
supercat@casperkitty.com writes:
> On Wednesday, November 22, 2017 at 11:46:04 AM UTC-6, James R. Kuyper wrote:
>> If someone tries to pass an empty string represented by a null pointer
>> to this routine for option 1, they're not going to be happy with the
>> resulting behavior. How should I re-write the code to work under such a
>> modified version of C? That's a rhetorical question - I know precisely
>> what I'd have to do to implement the desired functionality in a language
>> that confuses null pointers with pointers to empty strings - and I don't
>> like the idea of having to do that.
>
> The only way in which the C language cares about the concept of a "string"
> is when quoted literals appear within source text.
If by "the C language" you mean the core language, as specified in
section 6 of the standard, I believe that's correct. Of course numerous
standard library functions require pointers to strings as arguments, and I
would argue that the standard library (section 7) is just as much a part
of C as the core language is.
(To forestall any objection about the phrase "pointers to strings", the
term is defined in 7.1.1p1.)
> Some library functions
> will read a sequence of characters until they encounter a zero byte or (in
> some case) a specified number of characters have been read, but most real
> applications that need strings need some kind of string "container" with
> stronger semantics than a char*, but no single kind of container is optimal
> for all uses.
>
> Any code that needs to be able to distinguish between an unassigned string
> and an assigned string containing zero characters would be free to use a
> pointer to a zero byte for the latter case. On the other hand, code which
> *doesn't* need to make such a distinction may benefit from being able to
> have a null pointer treated as an empty string in certain cases. Because
> it may sometimes be useful to trap if a pointers is *unexpectedly* null,
> I can see uses for having a function which may trap (or do whatever) if
> given a null pointer in addition to one which would be specified as treating
> a null pointer as an empty string. Rather than try to argue about which
> behavior should be supported by a single function, recognize the usefulness
> of both behaviors in different cases.
How many variants of each standard function do you want? How big would
the standard be if all your suggestions were adopted?
Certainly an application can treat a null pointer as if it denoted a
pointer to an empty string, though I don't think I'd do so myself.
But I don't believe that it would be worthwhile to duplicate every C
library function that works with strings, creating a new version (with a
distinct name) that treats a null pointer as if it pointed to an empty
string, all to support an idiom that's rarely used.
Anybody who wants to write a string library that treats null pointers as
pointers to empty strings is, of course, free to do so. If it turned
out to be sufficiently useful (which I personally doubt), that would be
an argument in favor of making a change to the standard.
--
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 | Next — Previous in thread | Next in thread | Find similar
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