Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c > #123457
| Newsgroups | comp.lang.c |
|---|---|
| Date | 2017-11-24 14:33 -0800 |
| References | (18 earlier) <lnr2sqrlvs.fsf@kst-u.example.com> <88aa44ee-4547-4746-8542-fbc31064f51b@googlegroups.com> <lnmv3dsvp8.fsf@kst-u.example.com> <413e8f34-5223-4daf-a06b-547b82823e1a@googlegroups.com> <fJKRB.4914$qD6.2286@fx04.am4> |
| Message-ID | <10d1701d-8dce-4901-a1eb-e1ed89dcc44f@googlegroups.com> (permalink) |
| Subject | Re: High level programming in C |
| From | supercat@casperkitty.com |
On Thursday, November 23, 2017 at 7:37:31 PM UTC-6, Bart wrote:
> On 24/11/2017 00:42, supercat@casperkitty.com wrote:
> > The Windows Common Object Model (COM) is probably the most widely-used
> > one. Its string type represents strings as a pointer to a sequence of
> > bytes which is preceded by the length (four bytes, little-endian) and
> > some other information, but is designed to inter-operate smoothly with
> > C strings.
>
> I tried to look it up but got lost in complexities (can nobody create
> anything simple any more apart from me?).
>
> But, if the string follows immediately after the length and other info,
> then I don't think this model will work well with substrings. So you
> can't point into the 4-character "holo" substring here:
>
> (000011 xx xx "bartholomew")
>
> without extracting a separate copy that is preceded by its own
> descriptor, and ending up with (000004 xx xx "holo").
>
> To pass such strings and substrings around without worrying about
> managing the memory or keeping track of references to shared data, then
> a simple slice like this:
>
> (length, pointer) // 8 or 16 bytes
>
> would be straightforward. It might suit C more than the heavyweight
> solutions. Here, zero length strings can be (0,NULL).
If one wishes to pass the tail of a COM string to a function that expects a
zero-terminated string, one may simply offset the pointer and pass that.
If the function is going to expect to access the length field from a COM
string, it will be necessary to make a copy of the string in question.
The approach I'd like to see would be to use a length-prefixed string format
where different ranges of values for the prefix byte mean different things.
In simplest case, say that a value 0-254 is a length, and a value of 255
would indicate the following structure:
struct string_descriptor {
unsigned char FFbyte;
size_t length;
char *text;
}
Code which had a string object that was going to be valid at least until
it returned, could then do:
// Call "foo" with a string holding characters 4, 5, and 6 of the
// supplied string, or as many of them as exist.
struct string_descriptor my_substring;
copy_string_descriptor(&my_substring, orig_string_ptr);
if (my_substring.length < 4)
my_substring.length=0;
else
{
my_substring.text += 4;
my_substring.length -= 4;
if (my_substring.length > 3)
my_substring.length = 3;
}
foo(&my_substring);
If *orig_string_ptr is 0..254, my_substring.length would be loaded with
*orig_string_ptr, and my_substring.length would get orig_string_ptr+1.
Otherwise, my_substring would simply be copied from *(struct string descriptor*)orig_string_ptr. In any case, my_substring.FFbyte would be
set to 255, allowing &my_substring.FFbyte to be passed to other code
that expects to deal with strings.
Note that the time required for the substring-clipping approach would
be independent of the length of the original string or the desired
substring, since no copying of actual string data would be required.
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