* Re: simple question - how to emulate void * ?
1998-10-23 0:00 ` Dale Stanbrough
@ 1998-10-22 0:00 ` Hans Marqvardsen
1998-10-23 0:00 ` John McCabe
1998-10-22 0:00 ` Hans Marqvardsen
` (2 subsequent siblings)
3 siblings, 1 reply; 24+ messages in thread
From: Hans Marqvardsen @ 1998-10-22 0:00 UTC (permalink / raw)
Dale Stanbrough wrote:
>
> --------------------------------------------------------
> with System; use System;
> with System.Storage_Elements; use System.Storage_Elements;
> with System.Address_To_Access_Conversions;
> with text_io; use text_IO;
>
> procedure PB is
>
> package Char_Address is new System.Address_To_Access_Conversions (Character);
> use Char_Address;
>
> procedure Print_Bytes (Buffer : System.Address; Length : Integer)
> is
> Temp : System.Address;
> begin
> Temp := Buffer;
> for i in 1..Length loop
> Text_IO.Put (To_Pointer (Temp).all);
> Temp := Temp + 1;
> end loop;
> end Print_Bytes;
>
> X : String := "Hello There";
> begin
>
> Print_Bytes (X'Address, X'Length);
>
> end;
> --------------------------------------------------------
> (compiled and works using Gnat3.10, Sparc Solaris).
> Dale
Strangely, using OA 7.1.1 it wont compile.
Error message:
Temp := Temp + 1;
Line 20 col 23: the expression is ambiguous.
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: simple question - how to emulate void * ?
1998-10-22 0:00 ` Hans Marqvardsen
@ 1998-10-23 0:00 ` John McCabe
1998-10-23 0:00 ` Ed Falis
1998-10-23 0:00 ` dennison
0 siblings, 2 replies; 24+ messages in thread
From: John McCabe @ 1998-10-23 0:00 UTC (permalink / raw)
Hans Marqvardsen <hm@ddre.dk> wrote:
Works on Irix 6.4, GNAT 3.07 (?)
<..snip..>
>> Temp := Temp + 1;
>Strangely, using OA 7.1.1 it wont compile.
>Error message:
> Temp := Temp + 1;
> Line 20 col 23: the expression is ambiguous.
In the OA package System, what is type Address declared as?
--
Best Regards
John McCabe
---------------------------------------------------------------------
Marconi Electronic Systems
Simulation & Training Division
=====================================================================
Not necessarily my company or service providers opinions.
=====================================================================
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: simple question - how to emulate void * ?
1998-10-23 0:00 ` John McCabe
@ 1998-10-23 0:00 ` Ed Falis
1998-10-23 0:00 ` dennison
1998-10-24 0:00 ` Dale Stanbrough
1998-10-23 0:00 ` dennison
1 sibling, 2 replies; 24+ messages in thread
From: Ed Falis @ 1998-10-23 0:00 UTC (permalink / raw)
> Hans Marqvardsen <hm@ddre.dk> wrote:
>
> Works on Irix 6.4, GNAT 3.07 (?)
>
> <..snip..>
>
> >> Temp := Temp + 1;
>
> >Strangely, using OA 7.1.1 it wont compile.
> >Error message:
> > Temp := Temp + 1;
> > Line 20 col 23: the expression is ambiguous.
>
In OA, both System and System.Storage_Units declare "+" operators with Address and Integer or Storage_Offset respectively. Since there are use clauses
for both units, the compiler doesn't know how to interpret the numeric literal "1" on the right hand side of the expression.
So, eliminate one of the use clauses, or qualify the literal, e.g. Integer'(1) or Storage_Offset'(1), and the code will compile and execute.
My guess is that the address arithmetic in OA System was left in for compatibility with the Alsys Ada 83 compilers it replaced.
- Ed Falis
Aonix
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: simple question - how to emulate void * ?
1998-10-23 0:00 ` Ed Falis
@ 1998-10-23 0:00 ` dennison
1998-10-24 0:00 ` Joe Wisniewski
1998-10-25 0:00 ` dewar
1998-10-24 0:00 ` Dale Stanbrough
1 sibling, 2 replies; 24+ messages in thread
From: dennison @ 1998-10-23 0:00 UTC (permalink / raw)
In article <1104_909142646@DZOG-CHEN>,
falis@ma.aonix.com (Ed Falis) wrote:
> In OA, both System and System.Storage_Units declare "+" operators with Address
and Integer or Storage_Offset respectively. Since there are use clauses
> for both units, the compiler doesn't know how to interpret the numeric literal
"1" on the right hand side of the expression.
>
> So, eliminate one of the use clauses, or qualify the literal, e.g. Integer'(1)
or Storage_Offset'(1), and the code will compile and execute.
>
One more poor soul burned by the evil "use" clause...
--
T.E.D.
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: simple question - how to emulate void * ?
1998-10-23 0:00 ` dennison
@ 1998-10-24 0:00 ` Joe Wisniewski
1998-10-25 0:00 ` dewar
1 sibling, 0 replies; 24+ messages in thread
From: Joe Wisniewski @ 1998-10-24 0:00 UTC (permalink / raw)
There is an analogous situation to this "use" problem with
named notation for a subprogram that is overloaded. I can't
quite remember the situation exactly. Ugh, I can't quite remember
the situation. If someone;s run into this recently, it would be interesting
to look at.
Joe
dennison@telepath.com wrote in message <70q89d$io1$1@nnrp1.dejanews.com>...
>In article <1104_909142646@DZOG-CHEN>,
> falis@ma.aonix.com (Ed Falis) wrote:
>> In OA, both System and System.Storage_Units declare "+" operators with
Address
>and Integer or Storage_Offset respectively. Since there are use clauses
>> for both units, the compiler doesn't know how to interpret the numeric
literal
>"1" on the right hand side of the expression.
>>
>> So, eliminate one of the use clauses, or qualify the literal, e.g.
Integer'(1)
>or Storage_Offset'(1), and the code will compile and execute.
>>
>
>One more poor soul burned by the evil "use" clause...
>
>--
>T.E.D.
>
>-----------== Posted via Deja News, The Discussion Network ==----------
>http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: simple question - how to emulate void * ?
1998-10-23 0:00 ` dennison
1998-10-24 0:00 ` Joe Wisniewski
@ 1998-10-25 0:00 ` dewar
1 sibling, 0 replies; 24+ messages in thread
From: dewar @ 1998-10-25 0:00 UTC (permalink / raw)
In article <70q89d$io1$1@nnrp1.dejanews.com>,
dennison@telepath.com wrote:
> In article <1104_909142646@DZOG-CHEN>,
> falis@ma.aonix.com (Ed Falis) wrote:
> > In OA, both System and System.Storage_Units declare "+" operators with
Address
> and Integer or Storage_Offset respectively. Since there are use clauses
> > for both units, the compiler doesn't know how to interpret the numeric
literal
> "1" on the right hand side of the expression.
> >
> > So, eliminate one of the use clauses, or qualify the literal, e.g.
Integer'(1)
> or Storage_Offset'(1), and the code will compile and execute.
> >
>
> One more poor soul burned by the evil "use" clause...
That does not seem exactly fair in this case. It is a mistake in an Ada 95
compiler to provide address arithmetic in System. Yes, some compilers do
this for compatibility with implementation dependent additions to their
System packages for Ada 83, but it is a huge pain for Ada 95 programmers.
We ran across this with the DEC version of System which also supplies address
arithmetic (and lots of other stuff) in their System, and it definitely
inteferes with many existing programs. The danger here is not in using a
USE clause per se, but in the assumption that "use System" only gets you
the stuff you see in the RM. Unfortunately, that is not necessarily the
case, since implementors are allowed to add anything they like to System.
In GNAT, the standard version of System that you get without doing anything
special is the one in the RM. If you need an extended version of System with
non-standard extensions, then you can use the GNAT pragma Extend_System,
naming a package that provides the extensions. We distribute a standard
package System.Aux_DEC that provides the DEC Ada 83 extensions, but
additional extensions can be provided.
It would for example be possible to provide a package that added the OA
extensions, and this is probably easy to do. We just haven't done it because
there hasn't been any demand for this (our customers are typically writing
new Ada 95 programs, or porting legacy code from other than Alsys systems,
or porting standard Ada code that does not use these extensions) so the
issue has not arisen. Note that it is definitely good Ada practice NOT
to use System dependent extensions in Ada programs.
For those not allergic to use clauses, it is a bit of a pity not to allow
yourself to "use system", but with compilers around that add
implementation dependent stuff to System, it may cause difficulties.
Note that Ada is carefully designed so that the "evil" effects of using USE
in a case like this are limited to the introduction of ambiguities that are
(a) clearly diagnosed by any decent compiler and (b) easily fixed, so that's
not exactly so evil if you know what you are doing!
Note of course that address arithmetic is something that should in any case
ONLY be used by Ada programmers who know what they are doing (in practice of
course, as one can tell from the somewhat distasteful subject line of this
thread, distasteful because void * is in some ways a crystallization of
what is wrong with C, people often try to use address arithmetic in
inappropriate cases!)
Robert Dewar
Ada Core Technologies
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: simple question - how to emulate void * ?
1998-10-23 0:00 ` Ed Falis
1998-10-23 0:00 ` dennison
@ 1998-10-24 0:00 ` Dale Stanbrough
1998-10-24 0:00 ` Robert A Duff
1998-10-24 0:00 ` Tucker Taft
1 sibling, 2 replies; 24+ messages in thread
From: Dale Stanbrough @ 1998-10-24 0:00 UTC (permalink / raw)
Ed Falis wrote:
"In OA, both System and System.Storage_Units declare "+" operators with Address
and Integer or Storage_Offset respectively. Since there are use clauses
for both units, the compiler doesn't know how to interpret the numeric literal
"1" on the right hand side of the expression.
So, eliminate one of the use clauses, or qualify the literal, e.g. Integer'(1)
or Storage_Offset'(1), and the code will compile and execute.
My guess is that the address arithmetic in OA System was left in for
compatibility with the Alsys Ada 83 compilers it replaced.
- Ed Falis
Aonix"
This is then a problem with Ada, that the legality of calling a routine in
a child package can be affected by the exact definition of a type defined
as "implementation defined".
package System has...
type Address is <implementation defined>;
package System.Storage_Elements is...
address manipulation routines such as +, - and mod.
If Address is defined as an integer type, then it automatically gets all
of the numeric operations inherited.
If Address is an access type, then it gets not much.
Perhaps it would have been better if the LRM specifically excluded these
operations from package System.Address, given the presence of
System.Storage_Elements. Perhaps we need to understand the rationale of
having
type Address is <impl. defined>
vs.
type Address is private;
I certainly haven't hit this particular problem before, and it _is_
an annoying "feature". Can anyone clarify this point for me?
Dale
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: simple question - how to emulate void * ?
1998-10-24 0:00 ` Dale Stanbrough
@ 1998-10-24 0:00 ` Robert A Duff
1998-10-24 0:00 ` Tucker Taft
1 sibling, 0 replies; 24+ messages in thread
From: Robert A Duff @ 1998-10-24 0:00 UTC (permalink / raw)
dale@cs.rmit.edu.au (Dale Stanbrough) writes:
> This is then a problem with Ada, ...
True.
>... Perhaps we need to understand the rationale of
> having
>
> type Address is <impl. defined>
>
> vs.
>
> type Address is private;
Making type Address private, with a portable set of operators, is
clearly preferable. The Ada 95 RM has Implementation Advice that
encourages that. However, we couldn't *require* it, because in Ada 83,
an implementation could put anything they liked into package System, and
we wanted allow those implementations to have an upward-compatible
System.
A good rule of thumb is to never say "use System;", because you never
know what junk might be in System, and might conflict with other use
clauses. That was good advice in Ada 83, too, since one might be using
different versions of System from different compilers.
At least this sort of error is found at compile time. The use-clause
rules prevent Beujolais effects -- that is, if there's a conflict
between, say, System."+" and System.Storage_Elements."+", then neither
one silently wins, but you get a compile-time error.
> I certainly haven't hit this particular problem before, ...
Perhaps because you never said "use System", but instead always
"System.Whatever".
- Bob
--
Change robert to bob to get my real email address. Sorry.
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: simple question - how to emulate void * ?
1998-10-24 0:00 ` Dale Stanbrough
1998-10-24 0:00 ` Robert A Duff
@ 1998-10-24 0:00 ` Tucker Taft
1 sibling, 0 replies; 24+ messages in thread
From: Tucker Taft @ 1998-10-24 0:00 UTC (permalink / raw)
Dale Stanbrough (dale@cs.rmit.edu.au) wrote:
: ...
: This is then a problem with Ada, that the legality of calling a routine in
: a child package can be affected by the exact definition of a type defined
: as "implementation defined".
: ...
: Perhaps it would have been better if the LRM specifically excluded these
: operations from package System.Address, given the presence of
: System.Storage_Elements. Perhaps we need to understand the rationale of
: having
: type Address is <impl. defined>
: vs.
: type Address is private;
: I certainly haven't hit this particular problem before, and it _is_
: an annoying "feature". Can anyone clarify this point for me?
In RM95 we tried to balance the requirements for upward compatibility
against the requirements for portability. In Ada 83, package System
became a dumping ground for all kinds of non-portable stuff. In Ada 95,
we tried to encourage vendors to put the non-portable stuff into
implementation-defined children of System. In particular, RM95 13.7(36)
and 13.7(37) permit implementation-defined additions to System, but
encourage the use of children instead, and encourage declaring Address as
a private type.
However, vendors with a large installed Ada 83 base had to make certain
choices based on their customer preferences. The adding operators
on type Address involve such a choice.
The net effect is that users who want to write portable code
have to reckon with the possibility that package System
might have extra stuff in it. Hence, minimize the use of
"use" on package System. A "use" on package System.Storage_Elements
(or a "use type" on System.Storage_Elements.Storage_Offset) should be
safe and portable, since no implementation-defined additions
are permitted to that package.
: Dale
--
-Tucker Taft stt@inmet.com http://www.inmet.com/~stt/
Intermetrics, Inc. Burlington, MA USA
An AverStar Company
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: simple question - how to emulate void * ?
1998-10-23 0:00 ` John McCabe
1998-10-23 0:00 ` Ed Falis
@ 1998-10-23 0:00 ` dennison
1 sibling, 0 replies; 24+ messages in thread
From: dennison @ 1998-10-23 0:00 UTC (permalink / raw)
In article <70pfpm$qe5@gcsin3.geccs.gecm.com>,
John McCabe <john@assen.demon.co.uk> wrote:
> In the OA package System, what is type Address declared as?
type Address is access Integer;
Null_Address : constant Address := null;
--
T.E.D.
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: simple question - how to emulate void * ?
1998-10-23 0:00 ` Dale Stanbrough
1998-10-22 0:00 ` Hans Marqvardsen
@ 1998-10-22 0:00 ` Hans Marqvardsen
1998-10-23 0:00 ` David C. Hoos, Sr.
1998-10-23 0:00 ` David C. Hoos, Sr.
3 siblings, 0 replies; 24+ messages in thread
From: Hans Marqvardsen @ 1998-10-22 0:00 UTC (permalink / raw)
Hello Craig!
Since you say, you're new to Ada,
here is 2 further hints regarding Dales program:
The 'Size attribute is defined for any data-element
giving its size in bits. Use 'Size instead of 'Length.
(remember to divide by Storage_Unit)
Probably the number 1 should be casted as type
Storage_offset before it is added to a System.address.
(At least the OA compiler says so)
With these inclusions, Dales program will truly do the job,
not only for strings, but for any data-type passed,
for example integers, floats or records.
(Compiles and works on OA 7.1.1, Windows NT)
Hans.
Sorry for not including Dales original program.
My Netscape wont allow more included text than new text.
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: simple question - how to emulate void * ?
1998-10-23 0:00 ` Dale Stanbrough
1998-10-22 0:00 ` Hans Marqvardsen
1998-10-22 0:00 ` Hans Marqvardsen
@ 1998-10-23 0:00 ` David C. Hoos, Sr.
1998-10-23 0:00 ` David C. Hoos, Sr.
3 siblings, 0 replies; 24+ messages in thread
From: David C. Hoos, Sr. @ 1998-10-23 0:00 UTC (permalink / raw)
The trouble with Dale's solution is that it doesn't meet Craig's requirement
that the data be able to be of any type.
Further, Dale's liberal use uf use clauses obscures the fact that To_Pointer
is really Char_Addr.To_Pointer, thus rendering the procedure Print_Bytes
suitable only for arrays of characters -- i.e. strings.
The solution at the end of this post does meet Craig's requirement. Because
my Print_Bytes procedure is type-independent, I print each byte's
hexadecimal value.
David C. Hoos, Sr.
Dale Stanbrough wrote in message ...
>Craig Allen wrote:
>
> Well, yes, I'm new to ada, and coming from C.
>
> Now, I have some simple functionality that I'd like to see, and can't
> figure out how to do it in Ada.
>
> in C, it goes like this:
>
> /* libfile.c */
>
> void print_bytes(void *buf, int len)
> {
> int i;
> char *c = buf;
> for (i=0; i<len; ++i) {
> putchar(c[i]);
> }
>
> return;
> }
>
> /* app.c */
> ...
> struct any_struct data;
> print_bytes(&data, sizeof (struct data));
> ...
>
> The lib can access byte for byte the data passed in regardless of the
> app's struct type. Now, Ada being such a strongly typed language, I
> have tried different things but just can't seem to figure out how to
> get this lib routine to work on my buffer, regardless of its type.
> I've come close with some generic functions, but can't seem to get the
> syntax acceptable for the compiler.
> Can someone point me in the right direction?"
>
>
>Try using the object's address...
>
>--------------------------------------------------------
>with System; use System;
>with System.Storage_Elements; use System.Storage_Elements;
>with System.Address_To_Access_Conversions;
>with text_io; use text_IO;
>
>
>procedure PB is
>
> package Char_Address is new System.Address_To_Access_Conversions
(Character);
> use Char_Address;
>
>
> procedure Print_Bytes (Buffer : System.Address; Length : Integer)
> is
> Temp : System.Address;
> begin
> Temp := Buffer;
> for i in 1..Length loop
> Text_IO.Put (To_Pointer (Temp).all);
> Temp := Temp + 1;
> end loop;
> end Print_Bytes;
>
>
>
> X : String := "Hello There";
>begin
>
> Print_Bytes (X'Address, X'Length);
>
>end;
>--------------------------------------------------------
>(compiled and works using Gnat3.10, Sparc Solaris).
>
>Also the function "To_Pointer" is an intrinsic function, so it won't
>incur any overhead (that i can see) for being called. All the package
>Address_To_Access_Conversion does is explicity enforces what C does
>implicity, and at the same cost (someone please correct me if i am
>wrong)).
>
>Note that X'Length will give you the number of _Components_ in an
>array, not the length (in bytes) of the array.
>
>You could also use streams, which (IMHO) is a much more versatile
>tool.
>
>Dale
--- begin file print_bytes.adb -------------------------
with Ada.Text_Io;
with System.Storage_Elements;
procedure Print_Bytes
(At_The_Address : System.Address;
Storage_Element_Count : Natural) is
Elements_Per_Line : constant System.Storage_Elements.Storage_Count := 8;
use type System.Storage_Elements.Storage_Offset;
package Storage_Element_Io is new
Ada.Text_Io.Modular_Io (System.Storage_Elements.Storage_Element);
The_Data : System.Storage_Elements.Storage_Array
(1 .. System.Storage_Elements.Storage_Count (Storage_Element_Count));
for The_Data'Address use At_The_Address;
begin
for E in The_Data'range loop
if (E mod Elements_Per_Line) = 1 then
Ada.Text_Io.New_Line;
end if;
Storage_Element_Io.Put
(Item => The_Data (E),
Width => 8,
Base => 16);
end loop;
end Print_Bytes;
--- end file print_bytes.adb -------------------------
--- begin file app.adb -------------------------
with print_bytes;
with System.Storage_Elements;
procedure App is
subtype Storage_Element is System.Storage_Elements.Storage_Element;
The_Data : constant array (Positive range <>) of Long_Float :=
(1.0, 2.0, 3.0, 4.0);
begin
Print_Bytes
(At_The_Address => The_Data (The_Data'First)'Address,
Storage_Element_Count => The_Data'Size / Storage_Element'Size);
end App;
--- end file app.adb -------------------------
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: simple question - how to emulate void * ?
1998-10-23 0:00 ` Dale Stanbrough
` (2 preceding siblings ...)
1998-10-23 0:00 ` David C. Hoos, Sr.
@ 1998-10-23 0:00 ` David C. Hoos, Sr.
3 siblings, 0 replies; 24+ messages in thread
From: David C. Hoos, Sr. @ 1998-10-23 0:00 UTC (permalink / raw)
The trouble with Dale's solution is that it doesn't meet Craig's requirement
that the data be able to be of any type.
Further, Dale's liberal use of use clauses obscures the fact that To_Pointer
is really Char_Addr.To_Pointer, thus rendering the procedure Print_Bytes
suitable only for arrays of characters -- i.e. strings.
The solution at the end of this post does meet Craig's requirement. Because
my Print_Bytes procedure is type-independent, I print each byte's
hexadecimal value.
David C. Hoos, Sr.
Dale Stanbrough wrote in message ...
>Craig Allen wrote:
>
> Well, yes, I'm new to ada, and coming from C.
>
> Now, I have some simple functionality that I'd like to see, and can't
> figure out how to do it in Ada.
>
> in C, it goes like this:
>
> /* libfile.c */
>
> void print_bytes(void *buf, int len)
> {
> int i;
> char *c = buf;
> for (i=0; i<len; ++i) {
> putchar(c[i]);
> }
>
> return;
> }
>
> /* app.c */
> ...
> struct any_struct data;
> print_bytes(&data, sizeof (struct data));
> ...
>
> The lib can access byte for byte the data passed in regardless of the
> app's struct type. Now, Ada being such a strongly typed language, I
> have tried different things but just can't seem to figure out how to
> get this lib routine to work on my buffer, regardless of its type.
> I've come close with some generic functions, but can't seem to get the
> syntax acceptable for the compiler.
> Can someone point me in the right direction?"
>
>
>Try using the object's address...
>
>--------------------------------------------------------
>with System; use System;
>with System.Storage_Elements; use System.Storage_Elements;
>with System.Address_To_Access_Conversions;
>with text_io; use text_IO;
>
>
>procedure PB is
>
> package Char_Address is new System.Address_To_Access_Conversions
(Character);
> use Char_Address;
>
>
> procedure Print_Bytes (Buffer : System.Address; Length : Integer)
> is
> Temp : System.Address;
> begin
> Temp := Buffer;
> for i in 1..Length loop
> Text_IO.Put (To_Pointer (Temp).all);
> Temp := Temp + 1;
> end loop;
> end Print_Bytes;
>
>
>
> X : String := "Hello There";
>begin
>
> Print_Bytes (X'Address, X'Length);
>
>end;
>--------------------------------------------------------
>(compiled and works using Gnat3.10, Sparc Solaris).
>
>Also the function "To_Pointer" is an intrinsic function, so it won't
>incur any overhead (that i can see) for being called. All the package
>Address_To_Access_Conversion does is explicity enforces what C does
>implicity, and at the same cost (someone please correct me if i am
>wrong)).
>
>Note that X'Length will give you the number of _Components_ in an
>array, not the length (in bytes) of the array.
>
>You could also use streams, which (IMHO) is a much more versatile
>tool.
>
>Dale
--- begin file print_bytes.adb -------------------------
with Ada.Text_Io;
with System.Storage_Elements;
procedure Print_Bytes
(At_The_Address : System.Address;
Storage_Element_Count : Natural) is
Elements_Per_Line : constant System.Storage_Elements.Storage_Count := 8;
use type System.Storage_Elements.Storage_Offset;
package Storage_Element_Io is new
Ada.Text_Io.Modular_Io (System.Storage_Elements.Storage_Element);
The_Data : System.Storage_Elements.Storage_Array
(1 .. System.Storage_Elements.Storage_Count (Storage_Element_Count));
for The_Data'Address use At_The_Address;
begin
for E in The_Data'range loop
if (E mod Elements_Per_Line) = 1 then
Ada.Text_Io.New_Line;
end if;
Storage_Element_Io.Put
(Item => The_Data (E),
Width => 8,
Base => 16);
end loop;
end Print_Bytes;
--- end file print_bytes.adb -------------------------
--- begin file app.adb -------------------------
with print_bytes;
with System.Storage_Elements;
procedure App is
subtype Storage_Element is System.Storage_Elements.Storage_Element;
The_Data : constant array (Positive range <>) of Long_Float :=
(1.0, 2.0, 3.0, 4.0);
begin
Print_Bytes
(At_The_Address => The_Data (The_Data'First)'Address,
Storage_Element_Count => The_Data'Size / Storage_Element'Size);
end App;
--- end file app.adb -------------------------
^ permalink raw reply [flat|nested] 24+ messages in thread