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.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,aeab6b16387b2612 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2001-07-15 23:51:38 PST Path: archiver1.google.com!newsfeed.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!newshub2.home.com!news.home.com!news1.rdc1.sfba.home.com.POSTED!not-for-mail From: tmoran@acm.org Newsgroups: comp.lang.ada Subject: Re: How to do it in Ada ? References: <9itna2$i5b$1@news.tpi.pl> X-Newsreader: Tom's custom newsreader Message-ID: Date: Mon, 16 Jul 2001 06:51:37 GMT NNTP-Posting-Host: 24.7.82.199 X-Complaints-To: abuse@home.net X-Trace: news1.rdc1.sfba.home.com 995266297 24.7.82.199 (Sun, 15 Jul 2001 23:51:37 PDT) NNTP-Posting-Date: Sun, 15 Jul 2001 23:51:37 PDT Organization: Excite@Home - The Leader in Broadband http://home.com/faster Xref: archiver1.google.com comp.lang.ada:9985 Date: 2001-07-16T06:51:37+00:00 List-Id: > int main(int argc, char **argv) > { > int *x; > int n; > > n = (argc==1)?1:atoi(argv[1]); > x = malloc (n*sizeof(int)); > for (x=0;x x[i]=0; > > /* ... */ > } The most natural Ada way is: with Ada.Command_Line; procedure Main is N : Integer; begin if Ada.Command_Line.Argument_Count = 0 then N := 1; else N := Integer'value(Ada.Command_Line.Argument(1)); end if; declare X : array(1 .. N) of Integer := (others=>0); begin .... end; end Main; > Something like that ... how to do such dynamic array allocation in Ada ? If you mean heap allocation, not just dynamic stack allocation, then: with Ada.Command_Line; procedure Main is N : Integer; type X_Array_Type is array(Integer range <>) of Integer; type Px_Type is access X_Array_Type; X : Px_Type; begin if Ada.Command_Line.Argument_Count = 0 then N := 1; else N := Integer'value(Ada.Command_Line.Argument(1)); end if; X := new X_Array_Type'((1 .. N => 0)); .... end Main;