Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!tut.cis.ohio-state.edu!ucbvax!ucsfcgl!seibel From: seibel@cgl.ucsf.edu (George Seibel) Newsgroups: comp.lang.fortran Subject: Re: f2c experiences? (really C vs fortran strings) Message-ID: <16414@cgl.ucsf.EDU> Date: 26 Nov 90 08:00:05 GMT References: <1990Nov25.204354.12324@ariel.unm.edu> <28393@usc> Sender: daemon@cgl.ucsf.edu Reply-To: seibel@cgl.ucsf.edu (George Seibel) Organization: Computer Graphics Lab, UCSF Lines: 27 In article <28393@usc> ajayshah@almaak.usc.edu (Ajay Shah) writes: > >I'm not used to thinking of fortran as being a place to do >string handling! :-) I think the most persistent myth in all of computing is the superiority of C over fortran for string handling. C is vastly superior for *byte* handling, but *bytes are not strings*. Fortran has string data types and string operators. C doesn't. It was probably a bad choice on the part of the designers of fortran 77 to use the term "CHARACTER" for what should perhaps have been called the "STRING" data type. Nevertheless, fortran CHARACTER variables are in fact strings, and the language contains powerful facilities for their manipulation. I've written elaborate parsers in both languages; in both cases I had to augment the existing string handling functionality with a couple of 5-line functions, i.e., neither language was "perfect", but neither language was "incapable". One thing that the C string approach works better for is dealing with arrays of strings with widely varying lengths. Here C allows you to save memory by using pointers to contiguous byte arrays, whereas the easy way to do it in fortran is with fixed-width strings. There are efficient fortran solutions as well, using indices into character arrays or substrings. All in all, when I think about the areas in which C is better than fortran, string handling is not one of them. George Seibel, UCSF seibel@cgl.ucsf.edu