comp.lang.ada
 help / color / mirror / Atom feed
From: Corey Minyard <minyard@acm.org>
Subject: Re: Waiver question
Date: 1997/04/30
Date: 1997-04-30T00:00:00+00:00	[thread overview]
Message-ID: <m2ohawzmcp.fsf@acm.org> (raw)
In-Reply-To: fxrafuwcjp.fsf@boole.enst-bretagne.fr



Laurent Guerby <Laurent.Guerby@enst-bretagne.fr> writes:

> 
> Corey Minyard <minyard@acm.org> writes:
> > [...] For instance, the following code (and I hope
> > the kind readers of the newsgroup excuse me for using C, but it is
> > more compact for this type of stuff):
> 
>    Sacrilege ! See below. ;-)
> 
> > int
> > main()
> > {
> >    int a[4];
> >    char *c;
> > 
> >    a[0] = 0; a[1] = 0; a[2] = 0; a[3] = 0;
> >    c = (char *) a;
> >    c[0] = 0x01;
> >    c[1] = 0x02;
> >    c[2] = 0x03;
> >    c[3] = 0x04;
> >    printf("%x %x %x %x\n", a[0], a[1], a[2], a[3]);
> >    return 0;
> > }
> 
>    Here a somewhat equivalent Ada code, people can judge the
> "compactness": 
> 
> with Ada.Text_IO;         use Ada.Text_IO;
> with Ada.Integer_Text_IO; use Ada.Integer_Text_IO;
> with Interfaces;          use Interfaces;
> procedure Main is
>    A : array (1..4) of Integer   := (others => 0);
>    C : array (1..4) of Integer_8 := (1, 2, 3, 4);   
>    for C'Address use A'Address;
> begin
>    Put (A (1), 12, 16);   Put (A (2), 12, 16);
>    Put (A (3), 12, 16);   Put (A (4), 12, 16);
>    New_Line;
> end Main;           

I stand corrected.  I actually don't know Ada that well and had
forgotten about what the "for" statement can do.  However, I could
have made the C just as compact, it just would have been harder to
read.

> 
>    Of course in Ada the "with" clauses are mandatory (not the case of
> #include in C. If you want to use the C printf, you can also do it, it
> removes a few Ada IO with clauses:
> 
> procedure printf (Fmt : String; A, B, C, D : Integer);
> pragma Import (C, printf);
> ...
> printf ("%x %x %x %x" & ASCII.LF, A (1), A (2), A (3), A (4));
> 
> > on the Alpha will print:
> > 	1020304 0 0 0
> > and on the C40 will print:
> > 	1 2 3 4
> > because on the C40 a char and an int are the same size because the
> > minimum size of any addressable unit is 32-bits.
> 
>    On Intel/Linux/GNAT I get
> 
>  16#4030201#       16#0#       16#0#       16#0# 
> 
>    or
> 
> 4030201 0 0 0

This is correct for Intel since it is little endian.

-- 
Corey Minyard               Internet:  minyard@acm.org
  Work: minyard@nortel.ca       UUCP:  minyard@wf-rch.cirr.com




  reply	other threads:[~1997-04-30  0:00 UTC|newest]

Thread overview: 45+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1997-04-18  0:00 Waiver question Ken Garlington
1997-04-19  0:00 ` Tom Moran
1997-04-20  0:00 ` Steve Doiel
1997-04-20  0:00 ` Dean Runzel
1997-04-22  0:00   ` Ken Garlington
1997-04-20  0:00 ` Robert Dewar
1997-04-21  0:00   ` Ken Garlington
1997-04-22  0:00     ` Ken Garlington
1997-04-23  0:00       ` Corey Minyard
1997-04-24  0:00         ` Richard Kenner
1997-04-28  0:00         ` Larry Kilgallen
1997-04-28  0:00           ` Corey Minyard
1997-04-29  0:00             ` Robert Dewar
1997-04-29  0:00             ` Kaz Kylheku
1997-04-29  0:00             ` Laurent Guerby
1997-04-30  0:00               ` Corey Minyard [this message]
1997-04-29  0:00           ` Robert Dewar
1997-04-29  0:00           ` Richard Kenner
1997-04-30  0:00             ` Robert A Duff
1997-05-01  0:00               ` Kaz Kylheku
1997-05-02  0:00                 ` Robert A Duff
1997-05-02  0:00                   ` Larry Kilgallen
1997-05-02  0:00                     ` Robert Dewar
1997-05-02  0:00                     ` Robert A Duff
1997-05-02  0:00                       ` Larry Kilgallen
1997-05-03  0:00                         ` Robert A Duff
1997-05-03  0:00                           ` Larry Kilgallen
1997-05-04  0:00                             ` Robert Dewar
1997-05-04  0:00                         ` Robert Dewar
1997-05-06  0:00                     ` John M. Mills
1997-04-30  0:00             ` Robert Dewar
1997-05-01  0:00               ` Larry Kilgallen
1997-05-07  0:00                 ` Bad .diff files in gnat-3.09 in Linux Benoit Jauvin-Girard
1997-05-09  0:00                   ` Albert K. Lee
1997-04-23  0:00     ` Waiver question Tarjei Jensen
1997-04-21  0:00 ` Robert I. Eachus
1997-04-21  0:00   ` Robert Dewar
1997-04-22  0:00     ` Robert I. Eachus
1997-04-23  0:00       ` Robert Dewar
1997-04-22  0:00   ` Ken Garlington
1997-04-23  0:00     ` Robert S. White
1997-04-24  0:00     ` Robert Dewar
1997-04-24  0:00       ` Steve Vestal
1997-04-25  0:00         ` Robert I. Eachus
1997-04-25  0:00         ` Ken Garlington
replies disabled

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