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: f5d71,d275ffeffdf83655 X-Google-Attributes: gidf5d71,public X-Google-Thread: 103376,d275ffeffdf83655 X-Google-Attributes: gid103376,public X-Google-Thread: 146b77,d275ffeffdf83655 X-Google-Attributes: gid146b77,public X-Google-Thread: 109fba,d275ffeffdf83655 X-Google-Attributes: gid109fba,public From: mike Subject: Re: Ada vs C++ vs Java Date: 1999/02/05 Message-ID: <79evj0$49g@drn.newsguy.com>#1/1 X-Deja-AN: 441022495 References: <369C1F31.AE5AF7EF@concentric.net> <369DDDC3.FDE09999@sea.ericsson.se> <369e309a.32671759@news.demon.co.uk> <77ledn$eu7$1@remarQ.com> <77pnqc$cgi$1@newnews.global.net.uk> <8p64spq5lo5.fsf@Eng.Sun.COM> <77t3ld$nou$1@nnrp1.dejanews.com> <79ce4s$lfq$1@nnrp1.dejanews.com> <79chc7$ko6@drn.newsguy.com> <36BAF083.6C413B3D@acenet.com.au> Organization: Newsguy News Service [http://www.newsguy.com] Newsgroups: comp.lang.ada,comp.lang.c++,comp.vxworks,comp.lang.java Date: 1999-02-05T00:00:00+00:00 List-Id: In article <36BAF083.6C413B3D@acenet.com.au>, Geoff says... > > >mike wrote: > >> C++ now, after becoming a standard, and with the standard library is a >> very safe language. > >Not quite! > >$ cat rat.c >#include >int* one () {return &(1);} >int* two () {return &(2);} > >void main (int argc, char** argv) { > int* one_ptr = one (); int* two_ptr = two (); > printf ("one = %d\n", *one_ptr); > one_ptr = one (); > printf ("two = %d\n", *two_ptr); >} > >$ ./rat >one = 2 >two = 1 > > >One C compiler I used issued a warning, the other didn't. > First, a compiler bug has nothing to do with the language. bugs are bugs. (what are you trying to do to return an address of a number any way? second, your example will not even compile under gcc 2.8 nor under egcs 1.0.3 $cat t10.cpp #include int* one () {return &(1);} int* two () {return &(2);} void main (int argc, char** argv) { int* one_ptr = one (); int* two_ptr = two (); printf ("one = %d\n", *one_ptr); one_ptr = one (); printf ("two = %d\n", *two_ptr); } $g++ -Wall t10.cpp t10.cpp: In function `int * one()': t10.cpp:2: non-lvalue in unary `&' t10.cpp:2: warning: control reaches end of non-void function `one()' t10.cpp: In function `int * two()': t10.cpp:3: non-lvalue in unary `&' t10.cpp:3: warning: control reaches end of non-void function `two()' t10.cpp: At top level: t10.cpp:5: warning: return type for `main' changed to `int' Third, you should always use a good C++ compiler, and compile with warning turned on. Fourth, your example is a C program, not a C++. >You might think this is a ridiculous example, but I have >torn my hair out trying to find bugs as stupid as this code. >I can't think how I could possibly code this in Ada. > it is possible to write ridiculous bad code in any language. >Then there's the write off the end of the array trick ... > again, using C++ standard library, it provides you with data structures ready to use so you dont have to build your own eveytime and make begineer errors. so use those. anyone nowadays still doing such silly errors as falling of the end of an array because they dont use standard STL containers, do not deserve to be programming in any language. The proper use of C++ with its standard library makes it very safe system to develop with. mike