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-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,aa7f494bf30adbc7 X-Google-Attributes: gid103376,public Path: g2news1.google.com!news1.google.com!newshub.sdsu.edu!newshosting.com!nx01.iad01.newshosting.com!newsfeed-east.nntpserver.com!nntpserver.com!newsfeed1.sea.pnap.net!newsfeed.pnap.net!brmea-news-1.sun.com!news1nwk.sfbay.sun.com!new-usenet.uk.sun.com!not-for-mail From: Ole-Hjalmar Kristensen Newsgroups: comp.lang.ada Subject: Re: [newbie] simple(?) data structures Date: 18 Jun 2004 11:51:04 +0200 Organization: Sun Microsystems Message-ID: References: <2j1e30Fsrg8vU1@uni-berlin.de> <2jao1qFvj2rgU1@uni-berlin.de> <2jc33qFv3sitU1@uni-berlin.de> <1087475845.607135@master.nyc.kbcfp.com> NNTP-Posting-Host: europa1.norway.sun.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: new-usenet.uk.sun.com 1087552265 12411 129.159.113.161 (18 Jun 2004 09:51:05 GMT) X-Complaints-To: usenet@new-usenet.uk.sun.com NNTP-Posting-Date: 18 Jun 2004 09:51:05 GMT User-Agent: Gnus/5.0808 (Gnus v5.8.8) Emacs/20.7 Xref: g2news1.google.com comp.lang.ada:1650 Date: 2004-06-18T09:51:05+00:00 List-Id: Hyman Rosen writes: > Jeffrey Carter wrote: > > If you've used C a lot, it's an even better idea to avoid pointers, > > so you can learn how many situations that require pointers in C do > > not require them in Ada. > > It would be nice if there was a tutorial explaining why this is so and > showing how to take C code with pointers and transform it into Ada code > without pointers. It's mainly about string handling, since that's where > most of C's pointer manipulation takes place. The other eliminatable > situation I can think of involves factory methods in OO when you don't > need to keep a created object around permanently, so that you can use > classwide types and return them by value. Then there's the usual bit > about stepping through an array by pointer instead of index, but that's > not a requirement in C, merely an optimization. > As you probably know, using a pointer instead of an index is not necessarily an optimization in all cases with modern compilers and processors. As usual, it depends... Another place where you can (usually) eliminate some pointer handling is when returning records with variable-sized fields from functions, like this example, snipped from real code. Whether this method is optimal for performance I do not know, but it surely eliminates memory (de)allocation problems. -- Log record header type Log_Record_Header is record This_Lsn : Lsn; -- Lsn of this record Prev_Lsn : Lsn; -- LSN of prev. record Time_Stamp : Time; -- Timestamp Resource_Manager : Rmid := Null_Rmid; -- Resource mgr ID Trans_Id : Trid := Null_Trid; -- Transaction ID Tran_Prev_Lsn : Lsn; -- Previous lsn for this transaction Master_Lsn : Lsn; -- If chunk of log record, refers to start Length : Log_Buffer_Index := 0; Total_Length : Log_Buffer_Index := 0; end record; -- Log record, as written to file type Log_Record (N : Log_Buffer_Index) is record Log_Header : Log_Record_Header; -- Header -- The log record contents Log_Body : Log_Buffer (1 .. N); Next_Lsn : Lsn := (Null_Lsn); -- Set by log_read_lsn end record; -- Public interface functions -- Read log record with given lsn function Log_Read_Lsn ( Seq_Number : Lsn ) return Log_Record; > Do you know of any such tutorial? No. -- C++: The power, elegance and simplicity of a hand grenade.