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.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 108717,a7c8692cac750b5e X-Google-Thread: 103376,703c4f68db81387d X-Google-Attributes: gid108717,gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news3.google.com!newshub.sdsu.edu!logbridge.uoregon.edu!usenet01.sei.cmu.edu!bb3.andrew.cmu.edu!lmtp2nntp!not-for-mail From: "Arthur J. O'Dwyer" Newsgroups: comp.programming,comp.lang.ada Subject: Re: C: [] vs * (was: 10 rules for benchmarking (was Re: Teaching new tricks to an old dog (C++ -->Ada))) Date: Tue, 15 Mar 2005 16:29:11 -0500 (EST) Organization: Carnegie Mellon, Pittsburgh, PA Message-ID: References: <112vb2t8eonuhed@corp.supernews.com> <1110422108.925127.54110@o13g2000cwo.googlegroups.com> <11329cb96h2p19f@corp.supernews.com> <113394jjvppao64@corp.supernews.com> <1133s3qnmqmbjfb@corp.supernews.com> <4232a9f7$0$26552$9b4e6d93@newsread4.arcor-online.net> <11369p5jrcc6835@corp.supernews.com> NNTP-Posting-Host: smtp.andrew.cmu.edu Mime-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed X-Trace: bb3.andrew.cmu.edu 1110922152 22971 128.2.10.83 (15 Mar 2005 21:29:12 GMT) X-Complaints-To: advisor@andrew.cmu.edu NNTP-Posting-Date: 15 Mar 2005 21:29:12 GMT In-Reply-To: Xref: g2news1.google.com comp.programming:17991 comp.lang.ada:9454 Date: 2005-03-15T21:29:12+00:00 List-Id: On Tue, 15 Mar 2005, Programmer Dude wrote: > Arthur J. O'Dwyer writes: > >> I think regardless of CTips' and Jim's points in this thread, the original >> code serves as an excellent argument against using [] in function headers; >> the extra "documentation" is more than offset by the decline in >> readability, as far as I'm concerned. > > Just as another datapoint, I feel exactly the opposite. I much prefer > the [] notation to signify that the pointer refers to more than one of > whatever it's pointing at. > > Nowadays, most of my "C" code is C++, so if I pass a "pointer" to a > single object (object in the C sense (or C++ sense, FTM)) now I'd use > a reference. But in my C days, foo(int* pi) meant a pointer to a single > int, whereas bar(int ai[]) is (a pointer to) an array of ints. I agree that that's the implicit "semantics" of [] versus *; I just find bar(int ai[]), with all those vertical things clustered so close together, to be much harder on the eyes --- and that's a bigger negative for me than the implicit "Look, an array!" semantics is a positive. Maybe that was clear the first time around; I just want to make sure we're on the same page. >>> Treating the address of any int >>> as the beginning of an array is a formula for buffer >>> overflow, as is demonstrated in this example. >> >> This example does not appear to contain any buffer oveflow. >> If you think it does, please point it out to me. I may have >> missed something. > > Maybe not in this example, but let's be fair. He said that treating > the address of *any* int is problematic. And it is. C cannot be > called a "safe" language. Safety must be imposed by the programmer. Sure. But Jim said, "as is demonstrated in this example." That's like saying, "Jumping a motorcycle across a canyon is dangerous because you could fall to your death, as demonstrated by Evel Knievel."[1] -Arthur, daredevil [1] - (who has /not/ fallen to his death, as of this posting, which shows why Jim's statement IMO was either misleading or indicative of a misapprehension)