comp.lang.ada
 help / color / mirror / Atom feed
From: "Randy Brukardt" <randy@rrsoftware.com>
Subject: Re: Writing Data to a file
Date: Thu, 15 Dec 2011 18:55:47 -0600
Date: 2011-12-15T18:55:47-06:00	[thread overview]
Message-ID: <jce4ul$q60$1@munin.nbi.dk> (raw)
In-Reply-To: 530c4f5e-3c00-4ad5-92de-a4faefad468d@p16g2000yqd.googlegroups.com

"awdorrin" <awdorrin@gmail.com> wrote in message 
news:530c4f5e-3c00-4ad5-92de-a4faefad468d@p16g2000yqd.googlegroups.com...

...
>So since all I have is a System.Address and offsets, I believe I have
>to cast/convert this a Stream_Element_Array.

Yes, probably.

>If I could only access POSIX.IO's write 'function', rather than the
>procedures, I wouldn't have to go through these hoops.
>Of course, that write function is the equivalent of what I'm trying to
>replace...

You're not making any sense. The only difference between the POSIX.IO 
procedures and the imported function is that POSIX.IO gets rid of the 
(unused) result. The parameters and the meaning are the same (I think - I 
haven't used POSIX interfaces ever).

>I'm not sure I see how the Stream_IO package could be used directly
>for this.

Once you've converted your address/length into a Stream_Element_Array, just 
call Write on the appropriate slice:

    Stream_IO.Write (File_Object, Buf (1 .. Buf_Last));

or even (given that your sample code already has set the correct length:

   Stream_IO.Write (File_Object, Buf);

The "problem" here is getting a Stream_IO file object rather than a handle 
(which means you'll need to change the Open/Create calls, wherever they 
are), but that should be pretty simple.

                                   Randy.

P.S. In looking at your original code, I realized that you never gave 
Buf_Last a value, so that's probably why your Write call is failing. (You're 
writing some random number of bytes, rather than the correct calculated 
number).

P.P.S. In Janus/Ada, at least, the address clause would not work because you 
would relocate the array descriptor rather than the data. GNAT probably is 
different on this point, but I would not be certain if the clause works.

P.P.P.S. The use of explicit Address should be avoided in new code, 
specifically because it is hard to do anything sensible with it. Use general 
access types (if the designated value is of a specific type) it at all 
possible. (And if not, I recommend use of A2A 
(Address_to_Access_Conversions - see 13.7.2).







  reply	other threads:[~2011-12-16  0:55 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-12-15 18:13 Writing Data to a file awdorrin
2011-12-15 18:32 ` Ludovic Brenta
2011-12-15 19:23   ` awdorrin
2011-12-16  0:55     ` Randy Brukardt [this message]
2011-12-16 13:30     ` Jacob Sparre Andersen
replies disabled

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