Re: Pascal vs C style string ?

Erkki Ruohtula <eru@tele.nokia.fi>
Tue, 28 Jun 1994 07:25:42 GMT

          From comp.compilers

Related articles
[3 earlier articles]
Re: Pascal vs C style string ? jhallen@world.std.com (1994-06-27)
Re: Pascal vs C style string ? ddean@robadome.com (1994-06-27)
Re: Pascal vs C style string ? boehm@parc.xerox.com (1994-06-27)
Re: Pascal vs C style string ? nandu@cs.clemson.edu (1994-06-27)
Re: Pascal vs C style string ? eifrig@beanworld.cs.jhu.edu (1994-06-28)
Re: Pascal vs C style string ? monnier@di.epfl.ch (Stefan Monnier) (1994-06-28)
Re: Pascal vs C style string ? eru@tele.nokia.fi (Erkki Ruohtula) (1994-06-28)
Re: Pascal vs C style string ? andrew@cee.hw.ac.uk (1994-06-28)
Re: Pascal vs C style string ? jhallen@world.std.com (1994-06-28)
Re: Pascal vs C style string ? larryr@pa.dec.com) (1994-06-28)
Re: Pascal vs C style string ? boehm@parc.xerox.com (1994-06-28)
Re: Pascal vs C style string ? cjmchale@dsg.cs.tcd.ie (1994-06-29)
Re: Pascal vs C style string ? nandu@cs.clemson.edu (1994-06-29)
[5 later articles]
| List of all articles for this month |
Newsgroups: comp.compilers
From: Erkki Ruohtula <eru@tele.nokia.fi>
Keywords: C, Pascal, design
Organization: Compilers Central
References: 94-06-214
Date: Tue, 28 Jun 1994 07:25:42 GMT

Strings that are prefixed by a length are more tolerant of some
styles of programming, since finding the length of the string
is a fast operation, especially if the compiler knows about the
string representation and can compile the expression length(string)
into a simple load instruction.


I have too often seen careless C code like


for (i = 0; i < strlen(very_long_string); ++i) {
        do_something_with(very_long_string[i]);
}


For those who do not know C, this loop unnecessarily scans through
the whole very_long_string at every iteration. It would be quite OK
if the length-prefixed representation were used. In theory, a smart
compiler could fix this, at least in some cases. I wonder if any
actual C compiler does it?


Erkki Ruohtula / Nokia Telecommunications Oy
eru@tele.nokia.fi / P.O. Box 33 SF-02601 Espoo, Finland
--


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.