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,FREEMAIL_FROM autolearn=unavailable autolearn_force=no version=3.4.4 X-Received: by 10.66.157.35 with SMTP id wj3mr566814pab.11.1392163012891; Tue, 11 Feb 2014 15:56:52 -0800 (PST) X-Received: by 10.50.234.163 with SMTP id uf3mr23265igc.4.1392163012608; Tue, 11 Feb 2014 15:56:52 -0800 (PST) Path: border1.nntp.dca3.giganews.com!backlog3.nntp.dca3.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!c10no18259181igq.0!news-out.google.com!vg8ni31igb.0!nntp.google.com!uq10no16728100igb.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Tue, 11 Feb 2014 15:56:52 -0800 (PST) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=66.126.103.122; posting-account=KSa2aQoAAACOxnC0usBJYX8NE3x3a1Xq NNTP-Posting-Host: 66.126.103.122 References: User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <9d08b5d0-012c-4b94-b8b9-ea6e83f2df4f@googlegroups.com> Subject: Re: character literals From: adambeneschan@gmail.com Injection-Date: Tue, 11 Feb 2014 23:56:52 +0000 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Original-Bytes: 4066 Xref: number.nntp.dca.giganews.com comp.lang.ada:184793 Date: 2014-02-11T15:56:52-08:00 List-Id: On Tuesday, February 11, 2014 2:27:57 PM UTC-8, ag...@drrob1.com wrote: > I have been having a difficulty in my code with character literals. >=20 > For example >=20 > IF ch in '0' .. '9' THEN >=20 > This gives an error because the compiler is complaining that it does > not know if I mean a character, wide_character, or wide_wide_character > for my literals. How do I indicate which I want? I don't think your compiler should not be giving an "ambiguous" error on th= e above IF statement. The literals '0' and '9' are indeed ambiguous, becau= se they are actually overloaded functions that could return Character, Wide= _Character, or Wide_Wide_Character, or possibly one or more user-defined en= umeration types; however, assuming "ch" is a variable, it will have a known= type, and I think that type can be used to resolve the types of the overlo= aded range. However, on checking the language rules, it's not 100% clear t= o me that that's the case. Neither compiler I tried this on reports an err= or, though. This is different, though: for Ch in '0' .. '9' loop because this loop statement *is* the declaration of Ch, so the compiler has= to be able to resolve the type just from the literals '0' and '9', and it = can't. However, this is legal: Start_Ch : Character; for Ch in Start_Ch .. '9' loop because now although '9' is ambiguous, the language will use the type of St= art_Ch to resolve the type of '9'. I don't think it's necessary (even from= a style standpoint) to include the type name in the "for" statement; other= s may differ. The first "loop" statement, which is ambiguous, was legal in Ada 83, when t= here was only one character type; when Wide_Character was added to Ada 95 [= Wide_Wide_Character wasn't added until Ada 2005], this became illegal, whic= h caused some compatibility headaches for existing code. =20 Also: type Traffic_Light is (Red, Yellow, Green); type RGB is (Red, Green, Blue); for Color in Red .. Green loop -- ambiguous, illegal for Color in Green .. Blue loop -- legal, since there is only one mea= ning -- of Blue However, I'd definitely recommend including the type name in a case like th= is. for Color in RGB range Green .. Blue loop Finally, the language does have one special rule: for I in 0 .. 9 loop The literals 0 and 9 could be resolved to any integer type, which would mak= e this ambiguous since there are normally multiple integer types visible in= the program (Integer, Long_Integer, Short_Integer, maybe types in Interfac= es if you "use" that packaged). But the language rules decree that the typ= e will be Integer in that case. This is a situation where some programmers= might recommend making the type Integer explicit. -- Adam