Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| From | Stephen Sprunk <stephen@sprunk.org> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: Pointer to structure |
| Date | 2014-12-27 17:56 -0600 |
| Organization | A noiseless patient Spider |
| Message-ID | <m7ngun$pfa$1@dont-email.me> (permalink) |
| References | (2 earlier) <chine.bleu-B9C546.04393821122014@news.eternal-september.org> <Iuzlw.227520$p95.10761@fx38.am4> <chine.bleu-CBB10B.05052221122014@news.eternal-september.org> <lHzlw.145625$c73.56007@fx27.am4> <chine.bleu-EBDAE6.05545421122014@news.eternal-september.org> |
On 21-Dec-14 07:55, Siri Crews wrote: > You could require all strings be UTF-8 encoded, and store 0x80+n in > the first byte, where n is the number of length bytes, maximum > length, current length, and UTF-8 characters. And a string that > starts with a zero byte is an empty string; a string that starts with > any other valid UTF-8 byte is a zero terminated string. And all pass > around as char*. That would let you use legacy ASCII and UTF-8 > strings and new counted length strings transparently. There are only two invalid code units for UTF-8, so how are you supposed to know by examining the first byte whether the string is NUL-terminated UTF-8 or "counted length"? Even ignoring that, there are many other character encodings, and many of them have _no_ invalid values that you could hijack. The world is not all UTF-8, unfortunately, and ASCII is pretty much irrelevant these days. (Much of the world is now "UTF-16", though a large fraction of that is actually UCS-2; even "UTF-8" is often CESU-8, though that's mostly a result of broken "UTF-16" systems.) In-band signaling is nearly always a bad idea; if you want to use counted length strings, just use the struct hack, and then you don't have to worry about accidentally passing one to a function that is expecting a NUL-terminated string or vice versa. S -- Stephen Sprunk "God does not play dice." --Albert Einstein CCIE #3723 "God is an inveterate gambler, and He throws the K5SSS dice at every possible opportunity." --Stephen Hawking
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Pointer to structure Dexterr <dejangru@gmail.com> - 2014-12-21 03:16 -0800
Re: Pointer to structure BartC <bc@freeuk.com> - 2014-12-21 12:09 +0000
Re: Pointer to structure Siri Crews <chine.bleu@yahoo.com> - 2014-12-21 04:39 -0800
Re: Pointer to structure BartC <bc@freeuk.com> - 2014-12-21 12:59 +0000
Re: Pointer to structure Siri Crews <chine.bleu@yahoo.com> - 2014-12-21 05:05 -0800
Re: Pointer to structure BartC <bc@freeuk.com> - 2014-12-21 13:12 +0000
Re: Pointer to structure Siri Crews <chine.bleu@yahoo.com> - 2014-12-21 05:55 -0800
Re: Pointer to structure BartC <bc@freeuk.com> - 2014-12-21 14:31 +0000
Re: Pointer to structure Siri Crews <chine.bleu@yahoo.com> - 2014-12-21 06:47 -0800
Re: Pointer to structure BartC <bc@freeuk.com> - 2014-12-21 20:10 +0000
Re: Pointer to structure Geoff <geoff@invalid.invalid> - 2014-12-21 10:00 -0800
Re: Pointer to structure Ben Bacarisse <ben.usenet@bsb.me.uk> - 2014-12-21 22:44 +0000
Re: Pointer to structure raltbos@xs4all.nl (Richard Bos) - 2014-12-21 18:01 +0000
Re: Pointer to structure BartC <bc@freeuk.com> - 2014-12-21 21:21 +0000
Re: Pointer to structure raltbos@xs4all.nl (Richard Bos) - 2014-12-22 12:11 +0000
Re: Pointer to structure Ben Bacarisse <ben.usenet@bsb.me.uk> - 2014-12-21 22:36 +0000
Re: Pointer to structure Stephen Sprunk <stephen@sprunk.org> - 2014-12-27 17:56 -0600
Re: Pointer to structure Siri Crews <chine.bleu@yahoo.com> - 2014-12-27 16:33 -0800
Re: Pointer to structure Stephen Sprunk <stephen@sprunk.org> - 2015-01-15 12:29 -0600
Re: Pointer to structure glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2014-12-22 00:50 +0000
Re: Pointer to structure Richard Damon <Richard@Damon-Family.org> - 2014-12-21 20:19 -0500
Re: Pointer to structure glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2014-12-22 06:23 +0000
Re: Pointer to structure gazelle@shell.xmission.com (Kenny McCormack) - 2014-12-22 12:03 +0000
Re: Pointer to structure gazelle@shell.xmission.com (Kenny McCormack) - 2014-12-21 13:20 +0000
Re: Pointer to structure Siri Crews <chine.bleu@yahoo.com> - 2014-12-21 05:40 -0800
Re: Pointer to structure Ben Bacarisse <ben.usenet@bsb.me.uk> - 2014-12-21 13:16 +0000
Re: Pointer to structure Barry Schwarz <schwarzb@dqel.com> - 2014-12-21 10:02 -0800
Re: Pointer to structure Keith Thompson <kst-u@mib.org> - 2014-12-21 12:25 -0800
Re: Pointer to structure Dexterr <dejangru@gmail.com> - 2014-12-21 15:07 -0800
csiph-web