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-Thread: 103376,64691254fcf844dd X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news3.google.com!news.glorb.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local01.nntp.dca.giganews.com!nntp.comcast.com!news.comcast.com.POSTED!not-for-mail NNTP-Posting-Date: Sat, 09 Apr 2005 15:54:42 -0500 From: tmoran@acm.org Newsgroups: comp.lang.ada Subject: Re: Translate from C References: X-Newsreader: Tom's custom newsreader Message-ID: Date: Sat, 09 Apr 2005 15:54:42 -0500 NNTP-Posting-Host: 67.161.24.234 X-Trace: sv3-P8dHTcDePGgyjvfLeADs8PU26bRVXT2sTMQqhjuEdQRIqVnwURin8HcawTcmJEMedkJS7ZqmHo0iyIt!JmZ4tz8fNKRlluKeo/PXIWcR2nxiW54wTJVCLto/ZkD8Nyy5ttYBMJERWSdzxg== X-Complaints-To: abuse@comcast.net X-DMCA-Complaints-To: dmca@comcast.net X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.32 Xref: g2news1.google.com comp.lang.ada:10369 Date: 2005-04-09T15:54:42-05:00 List-Id: >I've this code in C : http://www.a2lf.org/util.c >and i want to translate it in Ada; In Ada one would usually have "Destination := Source;" rather than doing a procedure call. But if it needs to be a procedure, procedure Copy(Source : in Interfaces.C.char_array; Destination : out Interfaces.C.char_array; N : in Natural) is begin Destination(Destination'first .. Destination'first+N-1) := Source(Source'first .. Source'first+N-1); end Copy; assuming you want to deal with C arrays rather than Ada Strings. Of course if you wanted to handle mixed types, eg, copy a 32 bit float to 4 8-bit chars, your friend's solution comes close. However, S : String (1 .. Bytes); may include bounds information as well as the data. You can avoid that possibility by making the S and D declarations as large, fixed size, strings, where you are careful to only touch the first Bytes bytes, eg S : String (Positive); -- fixed size array needs no dynamic bound info D : String (Positive); To avoid possible initialization (ie, destruction) of S and D, you should pragma Import(C, S); pragma Import(C, D); Also, in Ada you could replace the loop for I in S'Range loop D (I) := S (I); end loop; by D(1 .. Bytes) := S(1 .. Bytes);