comp.lang.ada
 help / color / mirror / Atom feed
From: "Steve" <nospam_steved94@comcast.net>
Subject: Re: Translate from C
Date: Mon, 11 Apr 2005 06:39:40 -0700
Date: 2005-04-11T06:39:40-07:00	[thread overview]
Message-ID: <tNWdnd1iIu0q4MffRVn-hA@comcast.com> (raw)
In-Reply-To: pan.2005.04.09.19.30.30.254343@a2lf.org

First:
  It is very un-Ada like to blindly copy values fromone address to another 
in Ada.
  In Ada you tend to think of things at a higher level than C.

Second:
  There are very rare cases where you do want to copy a block of memory from 
one address to another.
  In these cases there is a function in Interfaces.C.Pointers called 
"Copy_Array" that performs exactly this function.

It would be better if you described the functionality you're looking for. 
We often see questions on this group along the lines of "This is how I do it 
in C, how do I do it the same way in Ada?".  More often than not, the better 
question is "This is what I am doing in C, how do I do the same thing in 
Ada?".  Often Ada provides a better way of doing things that results in 
fewer bugs making it past the compiler.

Steve
(The Duck)


"Jean-Baptiste CAMPESATO" <camje_lemon@a2lf.org> wrote in message 
news:pan.2005.04.09.19.30.30.254343@a2lf.org...
> Hello,
> I've this code in C : http://www.a2lf.org/util.c
> and i want to translate it in Ada;
> A friend tried :
>   procedure Copy
>     (Source      : Address;
>      Destination : Address;
>      Bytes       : Natural)
>   is
>      S : String (1 .. Bytes);
>      D : String (1 .. Bytes);
>      for S'Address use Source;
>      for D'Address use Destination;
>   begin
>      for I in S'Range loop
>         D (I) := S (I);
>      end loop;
>   end Copy;
>
> Do you think it's Ok ?
>
> Thanks. 





      parent reply	other threads:[~2005-04-11 13:39 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-04-09 19:30 Translate from C Jean-Baptiste CAMPESATO
2005-04-09 20:54 ` tmoran
     [not found] ` <gkvg51de5t83scllh0sp7go8nmcfe3ede9@4ax.com>
2005-04-10  7:47   ` Jean-Baptiste CAMPESATO
2005-04-11 13:39 ` Steve [this message]
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox