From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,8c8bbb1419c8e81a X-Google-Attributes: gid103376,public From: Laurent Guerby Subject: Re: Waiver question Date: 1997/04/29 Message-ID: #1/1 X-Deja-AN: 238069683 Sender: guerby@boole.enst-bretagne.fr References: <33585385.C8D@lmtas.lmco.com> <1997Apr28.151327.1@eisner> Organization: ENST de Bretagne, Brest FRANCE Newsgroups: comp.lang.ada Date: 1997-04-29T00:00:00+00:00 List-Id: Corey Minyard 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; 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 > Corey Minyard Internet: minyard@acm.org > Work: minyard@nortel.ca UUCP: minyard@wf-rch.cirr.com -- Laurent Guerby , Team Ada. "Use the Source, Luke. The Source will be with you, always (GPL)."