Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!sharkey!atanasoff!hascall From: hascall@atanasoff.cs.iastate.edu (John Hascall) Newsgroups: comp.arch Subject: Re: String lengths Message-ID: <762@atanasoff.cs.iastate.edu> Date: 5 Feb 89 17:47:17 GMT References: <6133@columbia.edu> <5124@aldebaran.UUCP> <7@microsoft.UUCP> <213@nbires.nbi.com> <38@microsoft.UUCP> <219@nbires.nbi.com> <14331@cup.portal.com> Reply-To: hascall@atanasoff.cs.iastate.edu (John Hascall) Organization: Iowa State U. Computer Science Department, Ames, IA Lines: 31 In article <14331@cup.portal.com> PLS@cup.portal.com (Paul L Schauble) writes: >Since it was mentioned in the Endian Wars, does anyone know why C uses the >null terminated string rather than an explicit length? It seems like such >an odd choice considering that > - It removes a character from the character set, a source of many C > bugs, and Agreed. > - All machines I know of that have character string instructions want > the length of the string. This forces the string primitives to first > scan for null, a time wasting operation. I assume you mean something like: +------+---+---+---+---+---+---+---+---+---+---+---+---+---+ |length| H | E | L | L | O | , | | W | O | R | L | D | \n| +------+---+---+---+---+---+---+---+---+---+---+---+---+---+ but, what size would you use for "length", a byte? a word? a longword? I suspect that some of these machines' instructions expect different sized operands for the length. Also, to quote K&R: "C was originally designed ... on the DEC PDP-11", a machine with no string instructions. John Hascall ISU Comp Center