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.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no 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!news1.google.com!news.maxwell.syr.edu!news.glorb.com!mpls-transit-01.news.qwest.net!ply1.onvoy!upp1.onvoy!msc1.onvoy!onvoy.com!news.mmm.com!not-for-mail From: Programmer Dude Newsgroups: comp.programming,comp.lang.ada Subject: C: [] vs * (was: 10 rules for benchmarking (was Re: Teaching new tricks to an old dog (C++ -->Ada))) Date: Tue, 15 Mar 2005 12:37:57 -0600 Organization: Wrenn Productions, LTD 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> Reply-To: Programmer Dude NNTP-Posting-Host: 169.10.86.157 Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Newsreader: Forte Agent 2.0/32.652 Xref: g2news1.google.com comp.programming:17982 comp.lang.ada:9451 Date: 2005-03-15T12:37:57-06:00 List-Id: 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. >> 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. C in the hands of the less expert programmer is *dangerous* as any number of virii, trojans and worms have clearly demonstrated. So is C++, albeit maybe slightly less so (OTOH, its complexity makes it problematic for non-experts in other areas). If anything, I think it's better to acknowledge the dangers of any tool rather than downplay them. One of the reasons skydiving kills fewer participants (percentage wise) than SCUBA is that there's no misapprehension in anyone's mind that jumping out of an airplane is *extremely* dangerous. SCUBA is just swimming.