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,ed3864cb23152ae6 X-Google-Attributes: gid103376,public From: dweller@dfw.net (David Weller) Subject: Re: C++'s pointer vs Ada's Access type Date: 1996/08/01 Message-ID: <4tqn1a$gb8@dfw.dfw.net>#1/1 X-Deja-AN: 171427026 references: <31FFD4A6.41C6@afit.af.mil> organization: DFWNet -- Public Internet Access newsgroups: comp.lang.ada Date: 1996-08-01T00:00:00+00:00 List-Id: In article <31FFD4A6.41C6@afit.af.mil>, Ding-yuan Sheu wrote: > >However, there comes a problem. >In C++, ip can be a pointer that points to a integer array. >Therefore, C++ programmers can do the following initialization: > > int Array[100]; > ip = &Array; > for (i:=0;i++,99) { (*ip+i) = 0; } > >My question is how I can do the same thing in Ada by using ip >to initialize Array instead to directly initialize Array. > There are a lot of "implicit" types in C++, but not in Ada. To accomplish the code segment you have above, you must declare a type that is an unconstrained array of integers: type Int_Array is array(Natural range <>) of Integer; -- I use Natural as the index to conceptually match C's arrays Then you simply make a declaration: A : Int_Array(0..99) := (others=>0); No pointer arithmetic involved :-) (Although Ada does support it with System.Storage_Elements package) Did I answer the question, or misunderstand it? -- Visit the Ada 95 Booch Components Homepage: www.ocsystems.com/booch This is not your father's Ada -- lglwww.epfl.ch/Ada