Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!purdue!bu-cs!buengc!bph From: bph@buengc.BU.EDU (Blair P. Houghton) Newsgroups: comp.lang.c Subject: Re: strings Message-ID: <2858@buengc.BU.EDU> Date: 14 May 89 11:46:05 GMT References: <2846@tank.uchicago.edu> <5785@cbnews.ATT.COM> <10087@smoke.BRL.MIL> <1415@uw-entropy.ms.washington.edu> <17333@mimsy.UUCP> <10228@socslgw.csl.sony.JUNET> <10237@smoke.BRL.MIL> <10235@socslgw.csl.sony.JUNET> <1989May11.155935.22324@utzoo.uucp> <456@sdti.S Reply-To: bph@buengc.bu.edu (Blair P. Houghton) Followup-To: comp.lang.c Organization: Boston Univ. Col. of Eng. Lines: 61 In article <456@sdti.SDTI.COM> turner@sdti.UUCP (0006-Prescott K. Turner, Jr.) writes: >In article <1989May11.155935.22324@utzoo.uucp> henry@utzoo.uucp (Henry Spencer) writes: >>In article <10235@socslgw.csl.sony.JUNET> diamond@csl.sony.junet (Norman Diamond) writes: [...it's all in the ref's. I'm after this guy:...] > >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. Those ACM SIG* types are usually pretty clever, but if one can't come up with the obvious (see below), then this one wonders where that one learned what data were, and whether the full meaning of 'clever' doesn't apply... typdef struct { char *characters; int length; } string; #define assign_string(s,a) s.characters=a;\ s.length=strlen(s.characters); main() { string lunchbox; assign_string(lunchbox,"Batman"); /* Now all you need do is refer to lunchbox.length * when you need the length of the string * stored in lunchbox.characters... */ printf("%d\n",lunchbox.length); /* * If you think this is less efficient * computationally than the stuff your * 'intelligent' languages do with string * data, then you're sadly mistaken... * * If using lunchbox.length doesn't appeal to you, * try: */ printf("%d\n",stringlength(lunchbox); /* * where you've done * * #define stringlength(x) x.length * * somewhere above the call to stringlength. */ } --Blair "Too damn easy. I have _got_ to be missing some undercurrent in this stream of cruft..."