From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-0.5 required=5.0 tests=BAYES_00,INVALID_MSGID, PP_MIME_FAKE_ASCII_TEXT autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII X-Google-Thread: 103376,54c513170bafd693 X-Google-Attributes: gid103376,public From: Ole-Hjalmar Kristensen Subject: Re: Desirability of C++ Date: 2000/05/04 Message-ID: #1/1 X-Deja-AN: 619100548 Sender: ohk@gong2.clustra.com References: <390DEC7F.9429C82C@online.no><390E2A20.B647D0D6@maths.unine.ch> <8em8mb$evd$1@wanadoo.fr><390EEF24.BD36AA24@maths.unine.ch> <8eonat$sqj3@ftp.kvaerner.com> <8eoo6v$ers$1@wanadoo.fr> X-Complaints-To: abuse@telia.no X-Trace: news.telia.no 957439777 195.204.160.194 (Thu, 04 May 2000 13:29:37 CEST) Organization: Telia Internet Public Access NNTP-Posting-Date: Thu, 04 May 2000 13:29:37 CEST Newsgroups: comp.lang.ada Date: 2000-05-04T00:00:00+00:00 List-Id: "Pascal Obry" writes: > Tarjei T. Jensen a �crit dans le message <8eonat$sqj3@ftp.kvaerner.com>... > > > >C has only one string type. It works reasonably well. Probably the most > > Sorry but to me C has no string type. It has "char *" which is a pointer to > some > memory space! The consequence here is that there is no operator available ! > It's a pointer to an *array* of characters. Or a string could *be* an array of charcters. Sounds familiar? The difference is that the C standard library assumes that strings are null-terminated. > Even to compare two strings you have to write: > > if (strcmp (name1, name2) == 0) { > ... > } > > I do prefer: > > if name1 = name2 then > ... > end if; > > Pascal. > If you are complaining about the need to test against 0, the reason is here: strcmp(), strncmp() The strcmp() function compares two strings byte-by-byte, according to the ordering of your machine's character set. The function returns an integer greater than, equal to, or less than 0, if the string pointed to by s1 is greater than, equal to, or less than the string pointed to by s2 respectively. The sign of a non-zero return value is deter- mined by the sign of the difference between the values of the first pair of bytes that differ in the strings being compared. The strncmp() function makes the same comparison but looks at a maximum of n bytes. Bytes following a null byte are not compared. I agree that a comparison operator looks nicer, but in practice it does not really matter. I find that the C string library functions are fairly complete, and works well. > > --|------------------------------------------------------ > --| Pascal Obry Team-Ada Member > --| 45, rue Gabriel Peri - 78114 Magny Les Hameaux FRANCE > --|------------------------------------------------------ > --| http://perso.wanadoo.fr/pascal.obry > --| > --| "The best way to travel is by means of imagination" > > > -- E pluribus Unix