comp.lang.ada
 help / color / mirror / Atom feed
* Unchecked conversion of arrays?
@ 2004-05-13 22:51 Björn Persson
  2004-05-14 10:39 ` Wojtek Narczynski
  2004-05-16 19:44 ` Nick Roberts
  0 siblings, 2 replies; 6+ messages in thread
From: Björn Persson @ 2004-05-13 22:51 UTC (permalink / raw)


Let's say I have a Wide_String that I need to convert to an array of 
bytes. Each byte will of course contain half a Wide_Character, with the 
other half in the next byte. Will I have to copy one character at a time 
or is there a faster way to do this with representation clauses or 
something? I'm thinking Unchecked_Conversion won't be reliable, because 
if for example the byte array is packed and Wide_String is not, then (on 
a 32-bit machine) I'll get two bytes of garbage between every two bytes 
of character data.

-- 
Björn Persson

jor ers @sv ge.
b n_p son eri nu




^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Unchecked conversion of arrays?
  2004-05-13 22:51 Unchecked conversion of arrays? Björn Persson
@ 2004-05-14 10:39 ` Wojtek Narczynski
  2004-05-14 17:34   ` Georg Bauhaus
  2004-05-15  1:11   ` Jeffrey Carter
  2004-05-16 19:44 ` Nick Roberts
  1 sibling, 2 replies; 6+ messages in thread
From: Wojtek Narczynski @ 2004-05-14 10:39 UTC (permalink / raw)


Bj�rn,

> I'm thinking Unchecked Conversion won't be reliable, because 
> if for example the byte array is packed and Wide String is not, then (on 
> a 32-bit machine) I'll get two bytes of garbage between every two bytes 
> of character data.

Wide_String is packed, says gnatpsta. I don't know if it is part of
the standard.

Unchecked_Conversion will check sizes for you, so I don't think you
need to worry about garbage.

You do need to remember about endian-ness, though.

Regards,
Wojtek



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Unchecked conversion of arrays?
  2004-05-14 10:39 ` Wojtek Narczynski
@ 2004-05-14 17:34   ` Georg Bauhaus
  2004-05-15  1:11   ` Jeffrey Carter
  1 sibling, 0 replies; 6+ messages in thread
From: Georg Bauhaus @ 2004-05-14 17:34 UTC (permalink / raw)


Wojtek Narczynski <wojtek@power.com.pl> wrote:
:> I'm thinking Unchecked Conversion won't be reliable, because 
:> if for example the byte array is packed and Wide String is not, then (on 
:> a 32-bit machine) I'll get two bytes of garbage between every two bytes 
:> of character data.
 
 
: Unchecked_Conversion will check sizes for you, so I don't think you
: need to worry about garbage.

Maybe this article is helpful here:
 http://www.adapower.com/lang/accessmem.html
 
: You do need to remember about endian-ness, though.


-- Georg



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Unchecked conversion of arrays?
  2004-05-14 10:39 ` Wojtek Narczynski
  2004-05-14 17:34   ` Georg Bauhaus
@ 2004-05-15  1:11   ` Jeffrey Carter
  2004-05-15 10:20     ` Björn Persson
  1 sibling, 1 reply; 6+ messages in thread
From: Jeffrey Carter @ 2004-05-15  1:11 UTC (permalink / raw)


Wojtek Narczynski wrote:

> Wide_String is packed, says gnatpsta. I don't know if it is part of
> the standard.

ARM A.1 has the specification of Standard, which contains the following:

type Wide_String is array(Positive range <>) of Wide_Character;
pragma Pack(Wide_String);

-- 
Jeff Carter
"Sir Robin the-not-quite-so-brave-as-Sir-Lancelot,
who had nearly fought the Dragon of Angnor,
who nearly stood up to the vicious Chicken of Bristol,
and who had personally wet himself at the
Battle of Badon Hill."
Monty Python & the Holy Grail
68




^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Unchecked conversion of arrays?
  2004-05-15  1:11   ` Jeffrey Carter
@ 2004-05-15 10:20     ` Björn Persson
  0 siblings, 0 replies; 6+ messages in thread
From: Björn Persson @ 2004-05-15 10:20 UTC (permalink / raw)


Jeffrey Carter wrote:

> ARM A.1 has the specification of Standard, which contains the following:
> 
> type Wide_String is array(Positive range <>) of Wide_Character;
> pragma Pack(Wide_String);

Aha, thanks. I only looked at 3.6.3 (String Types), which didn't say 
anything about packing.

-- 
Björn Persson

jor ers @sv ge.
b n_p son eri nu




^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Unchecked conversion of arrays?
  2004-05-13 22:51 Unchecked conversion of arrays? Björn Persson
  2004-05-14 10:39 ` Wojtek Narczynski
@ 2004-05-16 19:44 ` Nick Roberts
  1 sibling, 0 replies; 6+ messages in thread
From: Nick Roberts @ 2004-05-16 19:44 UTC (permalink / raw)


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 704 bytes --]

"Bj�rn Persson" <spam-away@nowhere.nil> wrote in message
news:7_Soc.92431$dP1.290953@newsc.telia.net...

Let's say I have a Wide_String that I need to convert to an array of
bytes. Each byte will of course contain half a Wide_Character, with the
other half in the next byte. Will I have to copy one character at a time
or is there a faster way to do this with representation clauses or
something? I'm thinking Unchecked_Conversion won't be reliable, because
if for example the byte array is packed and Wide_String is not, then (on
a 32-bit machine) I'll get two bytes of garbage between every two bytes
of character data.

Have you considered using streams and Wide_String'Write?

-- 
Nick Roberts





^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2004-05-16 19:44 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-05-13 22:51 Unchecked conversion of arrays? Björn Persson
2004-05-14 10:39 ` Wojtek Narczynski
2004-05-14 17:34   ` Georg Bauhaus
2004-05-15  1:11   ` Jeffrey Carter
2004-05-15 10:20     ` Björn Persson
2004-05-16 19:44 ` Nick Roberts

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