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,1042f393323e22da X-Google-Attributes: gid103376,public From: clines@delete_this.airmail.net (Kevin Cline) Subject: Re: Any research putting c above ada? Date: 1997/05/11 Message-ID: #1/1 X-Deja-AN: 240791718 References: <208C9C61CA05C32B.65D82DC950AAA33A.D68E7B27EB42E98A@library-proxy.airnews.net> <3372D44E.5F44@sprintmail.com> X-Orig-Message-ID: <33773334.1493960@news.airmail.net> Organization: INTERNET AMERICA NNTP-Proxy-Relay: library.airnews.net Newsgroups: comp.lang.ada Date: 1997-05-11T00:00:00+00:00 List-Id: "John G. Volan" wrote: >Kevin Cline wrote: >> In C++, you would solve this >> problem by passing a reference to a container. > >And promptly run into bizarre undefined behavior, because the container >whose reference you were returning happened to be one you declared >locally on the stack: > > MyContainer& MyClass::myFunction () const { > MyContainer myContainer; > ... // build value in myContainer > return myContainer; // dangling reference returned after >destructor!!! > } > I didn't say you would RETURN a reference to a container. I said you would pass one. >...So don't turn your nose up so fast about the return-by-copy mechanism in >Ada95 (or in C++ for that matter). Sure, you lose some efficiency, but >you get a lot of safety from that! In C++, you would write something like: void Read_File_Lines(vector& lines, istream& in)