Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!cwjcc!tut.cis.ohio-state.edu!rutgers!att!chinet!les From: les@chinet.chi.il.us (Leslie Mikesell) Newsgroups: comp.lang.c Subject: Re: strings Message-ID: <8466@chinet.chi.il.us> Date: 16 May 89 17:58:57 GMT References: <10250@socslgw.csl.sony.JUNET> Reply-To: les@chinet.chi.il.us (Leslie Mikesell) Organization: Chinet - Public Access Unix Lines: 34 In article <10250@socslgw.csl.sony.JUNET> diamond@csl.sony.co.jp.csl.sony.co.jp (Norman Diamond) writes: >>If you want counted strings, C makes it relatively easy to provide >>them for yourself. >Yes. You throw away the C library (which I understand is part of the >proposed ANSI standard) and the language's definition of how strings >are represented, you define your own representation of strings, and >you implement your own library. This is perfectly fine. A strictly >conforming program is not required to use every feature or every >mis-feature of the standard; a program is allowed to be more strict. Why throw anything away? You can store the lengths elsewhere and still use the null-terminated representation that the library routines want to see. struct eg { unsigned int str_len; char *the_str; }; This way you only need to store the length when you think it will be useful later. The only problem occurs if you need to store a '\0' value as part of the character array, and then it is only a problem if you want to use the library string routines on that array. >Good luck porting other people's strictly conforming programs though. >They might use C strings. As well they should... The only real problem I see with the C library routines is that they generally don't return a length or pointer to the last character even though it would be trivial to do so. Thus if you want the length you have to make another function call (at least strlen doesn't return the same pointer you gave it). Les Mikesell