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=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,dab7d920e4340f12 X-Google-Attributes: gid103376,public From: kst@thomsoft.com (Keith Thompson) Subject: Re: C is 'better' than Ada because... Date: 1996/07/19 Message-ID: #1/1 X-Deja-AN: 169794443 sender: news@thomsoft.com (USENET News Admin @flash) x-nntp-posting-host: pulsar references: <31E402B4.55EC@csehp3.mdc.com> <4se1cl$mp@salyko.cube.net> <4sgeme$r32@salyko.cube.net> organization: Thomson Software Products, San Diego, CA, USA newsgroups: comp.lang.ada originator: kst@pulsar Date: 1996-07-19T00:00:00+00:00 List-Id: In <4sgeme$r32@salyko.cube.net> okellogg@cube.net (Oliver Kellogg) writes: > I had written: > > > function Replicate (C : Character; Times : Positive) return String is > > Buffer : String(1..Times) := (others => C); > > begin > > return Buffer; > > end Replicate; > > On second thought, > > #include > char *replicate (char c, int times) > { > char *buffer = (char *) malloc (times); > return (char *) memset (buffer, c, times); > } > > is not that much less elegant either :-) Elegant or not, it's probably incorrect (depending on what you're trying to do with the result). Your replicate function returns a pointer to an array of characters, but it's not a string unless you add a trailing nul character. Storage management is also a potential problem, which is handled automatically in Ada. -- Keith Thompson (The_Other_Keith) kst@thomsoft.com <*> TeleSoft^H^H^H^H^H^H^H^H Alsys^H^H^H^H^H Thomson Software Products 10251 Vista Sorrento Parkway, Suite 300, San Diego, CA, USA, 92121-2718 "As the most participatory form of mass speech yet developed, the Internet deserves the highest protection from government intrusion." -- ACLU v. Reno