Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| From | raltbos@xs4all.nl (Richard Bos) |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: Pointer to structure |
| Date | 2014-12-22 12:11 +0000 |
| Organization | Go wash your mouth. |
| Message-ID | <549809f2.6696156@news.xs4all.nl> (permalink) |
| References | (5 earlier) <lHzlw.145625$c73.56007@fx27.am4> <chine.bleu-EBDAE6.05545421122014@news.eternal-september.org> <rRAlw.160024$812.50144@fx20.am4> <54970945.1580718@news.xs4all.nl> <qRGlw.154996$Kl4.10765@fx01.am4> |
BartC <bc@freeuk.com> wrote: > On 21/12/2014 18:01, Richard Bos wrote: > > BartC <bc@freeuk.com> wrote: > > > >> How do you copy one pstring to another? The first byte will give the > >> current length, but not the maximum that has been allocated; how will it > >> know how much to copy? > > > > You don't. _It_ does, underneath the hood. Remember that this is not a > > Standard Pascal feature; it's a common but not completely standardised > > extension. > > I was commenting about this: > > unsigned char pstring[]; > > which looks nearer C than Pascal! The original Pascal will know the > maximum length as it's part of the type (so is implicit in the > underlying data structure). The C version won't have that, so can only > work if the maximum length is a constant value throughout the program, > or is added as part of the code that works with these arrays. Exactly. So this is an inferior solution, and the OP should learn to work with real C strings already. > > (It may have made it into Pascal Extended; I never looked > > enough into that /contradictio in terminis/ to know or care.) Some > > implementations may have had yet a third member; some may have just > > crashed if you cross the borders. In any case, length-indicated strings > > are a Wrong Idea all 'round. > > (No, they're a good idea in the right language, with several advantages. > But I admit they are a bit of a pain in C.) They have a built-in limit to the string length, and require extra behind-the-scenes bookkeeping from the compiler _even though_ you're expected to do the other half of it yourself. That's not a good idea in any language. Richard
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