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,LOTS_OF_MONEY autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,1cf653444208df72 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2001-10-09 08:05:57 PST Path: archiver1.google.com!news2.google.com!news1.google.com!sn-xit-02!supernews.com!newsfeed.direct.ca!look.ca!feed2.onemain.com!feed1.onemain.com!cyclone2.usenetserver.com!usenetserver.com!news01.optonline.net!news02.optonline.net.POSTED!not-for-mail From: "Mike Mohr" Newsgroups: comp.lang.ada References: <9pgr68$7pu1@news.cis.okstate.edu> <9phnic$9g5$1@nh.pace.co.uk> <5fkv7.134136$w7.19988807@news02.optonline.net> <9pski60j31@drn.newsguy.com> <9psrqv016j9@drn.newsguy.com> Subject: Re: ada vs. cpp X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2600.0000 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000 Message-ID: Date: Tue, 09 Oct 2001 14:56:45 GMT NNTP-Posting-Host: 24.188.177.13 X-Trace: news02.optonline.net 1002639405 24.188.177.13 (Tue, 09 Oct 2001 10:56:45 EDT) NNTP-Posting-Date: Tue, 09 Oct 2001 10:56:45 EDT Organization: Optimum Online Xref: archiver1.google.com comp.lang.ada:14025 Date: 2001-10-09T14:56:45+00:00 List-Id: "Robert*@" wrote in message news:9psrqv016j9@drn.newsguy.com... > In article , "Mike says... > > > > > > >> There is nothing equivelant in C++ to declaring a new type integer > >> with restricted range. It is simply not in the C++ language. > > Your original reply didn't say anything about type checking, your original reply objected to the fact that the ranges were hardcoded so I responded with that in mind. I fixed the exact problem you cited. "The difference is that in Ada the range itself is a separate type declaration. So, one can change the range type in one place and have it propgate all over. With your attempt, you hardcoded the range using magic numbers in the variable declaration itself, so if the same range is to be used somewhere else in the code, or in different variable declaration, you need to type it there too manually." In my response, I have shown how to "change the range in one place and have it propagate all over." yet in the popular style of this newsgroup you have added additional requirements to the problem only after I have presented a complete answer to the original problem :) > In ada, when you declare a type of a restricted range, the compiler and run-time > will check that variables of such type can have values in that range only. > subtype Code is Positive range 1 .. 4; subtype Arg is Positive range 6 .. 8; V2 : constant String := V1 (Arg) & '-' & V1 (Code); By all accounts I am a new Ada programmer, so I am a little confused by the syntax. It isn't clear to me how Code, and Arg function in the expression. Do strings effectively have a ( ) operator which takes a range as an argument? I read V1 (Arg) as V1.substring(Arg) in pseudo code. Arg seems to be a value rather than a type. Is range effectively a parameterized type? Perhaps this is wrong, if so please show me what is really happening. If my guess is accurate please show me how static/dynamic checking would be done in the first (Ada) case. What I want is a description or examples of those cases which would raise an error. You also point out that "There is nothing equivelant in C++ to declaring a new type integer with restricted range" I understand your point, yet it isn't clear to me in the original example, what specifically is an integer.