Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!ucbvax!agate!saturn!ucscc.UCSC.EDU!haynes From: haynes@ucscc.UCSC.EDU (Jim Haynes) Newsgroups: comp.arch Subject: Re: String lengths Message-ID: <6239@saturn.ucsc.edu> Date: 7 Feb 89 04:48:12 GMT References: <8876@alice.UUCP> Sender: usenet@saturn.ucsc.edu Reply-To: haynes@ucscc.UCSC.EDU (Jim Haynes) Organization: California State Home for the Weird Lines: 38 In article <8876@alice.UUCP> dmr@alice.UUCP writes: >The question arose: why does C use a terminating character for >strings instead of a count? > Since dmr has spoken I probably shouldn't even think of trying to add anything, but ... If we think of machine architecture there are historically several different ways that have been used to represent strings. 1) Put the characters in adjacent storage locations, and use a special character to delimit the end of the string. This goes back to at least IBM 702 or thereabouts. It is basically what is used in C; IBM just happened to use a character other than null. 2) Put the characters in adjacent storage locations, and reserve a bit per storage location to delimit string boundaries. This is found in IBM 1401-1410-7010 family and 1620. 3) Put the characters in adjacent storage locations, don't delimit the boundaries at all, and absorb the information about string length into the instruction stream. This is what's done in IBM 360 and a lot of other machines. In contrast to 1) and 2) it requires something like a simulation of 4) below to deal with varying length strings and dynamic allocation of storage. 4) Put the characters in adjacent storage locations and store information about starting address and length in a data structure for the purpose, a string descriptor. This is used in Burroughs B6500 and later machines of that family. The string is virtually delimited, in that you can't access it, or aren't supposed to, without going through the descriptor and observing the boundary. What's the difference between a string and an array of characters? Is it anything other than the set of operations that are provided to operate on it? haynes@ucscc.ucsc.edu haynes@ucscc.bitnet ..ucbvax!ucscc!haynes "Any clod can have the facts, but having opinions is an Art." Charles McCabe, San Francisco Chronicle