Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!rutgers!uwvax!tank!mimsy!chris From: chris@mimsy.UUCP (Chris Torek) Newsgroups: comp.lang.c Subject: Re: strings Message-ID: <17507@mimsy.UUCP> Date: 14 May 89 01:36:42 GMT References: <2846@tank.uchicago.edu> <5785@cbnews.ATT.COM> <10087@smoke.BRL.MIL> <456@sdti.SDTI.COM> Organization: U of Maryland, Dept. of Computer Science, Coll. Pk., MD 20742 Lines: 33 In article <456@sdti.SDTI.COM> turner@sdti.SDTI.COM (Prescott K. Turner) writes: >Diamond is right. C is worse because it specifies not just the operations on >string types and their meaning, but the representation of strings. As Paul >Abrahams put it in SIGPLAN Notices 23:10, "Some Sad Remarks About String >Handling in C", "C strings are not first class objects." He gives details of >how this prevents the clever from succeeding. It is true that strings---or rather, string constants; C does not have strings as a basic data type: they are merely a convention, which some programs (Emacs, e.g.) avoid---are second class objects. This is because a double-quoted string constant creates an unnamed array, and C's arrays are second-class. But this only prevents cleverness in a weak sense. If you prefer counted strings, you can create them: struct cstr { int len; char *data; }; #define CSTR(s) { sizeof(s) - 1, s } struct cstr hello = CSTR("hello world"); It is true that the compiler and run-time system cannot arbitrarily choose some alternative representation for C's strings, but neither can they choose other representations for any other form of array. The language is at least consistent. Incidentally, the average string (in the mythical average C program) is shorter than the average Dhrystone string. -- In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163) Domain: chris@mimsy.umd.edu Path: uunet!mimsy!chris