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-Thread: 103376,782af4edeb84c4b7 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news1.google.com!news3.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!wns13feed!worldnet.att.net!attbi_s22.POSTED!53ab2750!not-for-mail From: "Jeffrey R. Carter" Organization: jrcarter at acm dot org User-Agent: Thunderbird 1.5.0.7 (Windows/20060909) MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: basic basic ada question References: <1161268231.345231.242170@m73g2000cwd.googlegroups.com> <1qy643kz9ktss$.12j6z88wjcte2$.dlg@40tude.net> <1161272720.704725.208180@e3g2000cwe.googlegroups.com> In-Reply-To: <1161272720.704725.208180@e3g2000cwe.googlegroups.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Message-ID: <6WQZg.1028379$084.76409@attbi_s22> NNTP-Posting-Host: 12.201.97.213 X-Complaints-To: abuse@mchsi.com X-Trace: attbi_s22 1161288450 12.201.97.213 (Thu, 19 Oct 2006 20:07:30 GMT) NNTP-Posting-Date: Thu, 19 Oct 2006 20:07:30 GMT Date: Thu, 19 Oct 2006 20:07:30 GMT Xref: g2news2.google.com comp.lang.ada:7049 Date: 2006-10-19T20:07:30+00:00 List-Id: markww wrote: > Ok, am I understanding this correctly - if I just '#include" the > command line package: "with" is significantly different from simple text inclusion. Most of what you know from C/++ is wrong for Ada. The sooner you can stop thinking in C/++ and start thinking in Ada, the easier you will find it. > with Ada.Command_Line; use Ada.Command_Line; As a beginner, I would strongly recommend that you avoid "use", at least until you understand Ada's visibility rules better. > then the package defines the functions: > > function Argument_Count return Natural; > function Argument (Number : in Positive) return String; > > for me which I can use from then on? > > So in my little app I can just use them like: > > Number_Of_Elements := Argument(0); > > (assuming the 0th argument is the # of elements to allocate...) As you quoted, Argument's parameter Number has subtype Positive. Zero is not a value of Positive. So such a call will raise Constraint_Error. In Ada, as in life, we usually count or number things starting from 1. Getting away from the low-level, offset-oriented C mindset is part of learning to think in Ada. ARM A.15 says, "If the external execution environment supports passing arguments to a program, then Argument returns an implementation-defined value corresponding to the argument at relative position Number. If Number is outside the range 1..Argument_Count, then Constraint_Error is propagated." So, if you have a single argument, it will be number 1. If you have 2, they will be 1 and 2. And so on. It's a good idea to get familiar with Annex A. Second, Argument's return type is String. Assuming Number_Of_Elements is the same type as the value being assigned to it (String), assigning complete Strings is usually not a good idea, since source and target must be the same length. Finally, assuming that Number_Of_Elements is, as its name suggests, an object of a numeric type, source and target have different types, and the statement will result in a compilation error. -- Jeff Carter "I fart in your general direction." Monty Python & the Holy Grail 05