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,FREEMAIL_FROM autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,a4d2751f9487bd38 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-07-07 06:55:45 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!feed2.news.rcn.net!rcn!nntp.abs.net!uunet!dca.uu.net!ash.uu.net!spool.news.uu.net!not-for-mail Date: Mon, 07 Jul 2003 09:46:51 -0400 From: Hyman Rosen User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.5a) Gecko/20030611 Thunderbird/0.1a X-Accept-Language: en-us, en MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Real data for a change in the assignment operators and Bounded_String discussions. References: <3F04F778.5090305@attbi.com> In-Reply-To: Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Organization: KBC Financial Products Message-ID: <1057585611.821825@master.nyc.kbcfp.com> Cache-Post-Path: master.nyc.kbcfp.com!unknown@nightcrawler.nyc.kbcfp.com X-Cache: nntpcache 3.0.1 (see http://www.nntpcache.org/) NNTP-Posting-Host: 204.253.250.10 X-Trace: 1057585611 15423 204.253.250.10 Xref: archiver1.google.com comp.lang.ada:40103 Date: 2003-07-07T09:46:51-04:00 List-Id: Georg Bauhaus wrote: > : Well, let's see (error checking left out): > Indeed ;-) The Ada program didn't check for sucessful file opens, and didn't check for Storage_Error, so I did the same in my C code. > The program has a leak. Your program has a leak. The C version necessarily differs from the Ada version in that it must allocate memory on the heap, so the returned pointer must be freed by the caller. > while (1) > _1st_line = first_line_of_file(TEST_FILE); > fputs(_1st_line, stdout); Instead, while (1) { _1st_line = first_line_of_file(TEST_FILE); fputs(_1st_line, stdout); free(_1st_line); } > and a few "(char*)realloc(...)" to first_line_of_file(). Unnecessary in C code, provided you include the correct header file. Realloc returns a void*, which in C converts to any other pointer without a cast.