comp.lang.ada
 help / color / mirror / Atom feed
From: Adam Beneschan <adambeneschan@aol.com>
Subject: Re: Ambiguous expressions - Help!
Date: Tue, 24 Sep 2013 11:43:45 -0700 (PDT)
Date: 2013-09-24T11:43:45-07:00	[thread overview]
Message-ID: <052de5da-75dc-486b-83e9-4f717d8e0ab7@googlegroups.com> (raw)
In-Reply-To: <9afe7143-873f-4ae9-a387-424a9f858827@googlegroups.com>

On Tuesday, September 24, 2013 11:15:35 AM UTC-7, Eryndlia Mavourneen wrote:
> On Tuesday, September 24, 2013 12:38:34 PM UTC-5, Mike H wrote:

> > I find it hard to believe that the compiler cannot distinguish between a
> > string and an array of characters. What am I doing wrong?

> An Ada String *is* an array of characters.  I didn't realize it, but apparently the String constant (in quotes) can be converted automatically into any vector of characters, even those not declared explicitly as "String"s.

A string literal can actually be converted to any array of an enumeration type, if the enumeration type has at least one character literal as one of its literals.  The classic example is:

    type Roman_Digit is ('I', 'V', 'X', 'L', 'C', 'D', 'M');
    type Roman_Numeral is array (Natural range <>) of Roman_Digit;
    R : Roman_Numeral := "MMXIII";

Roman_Numeral is called a "string type".  String, Wide_String, and Wide_Wide_String are other string types, as is Foo1.Grid_Type in the question.
When a string literal can be converted to more than one string type, it's ambiguous.  This does cause problems when there are two overloaded subprograms where one has a String parameter and another has a Wide_String or Wide_Wide_String parameter; the use of the string literal is ambiguous.  As Jeff answered, you have to specify which type you want:

    Foo2.Put_Line (Item => String'("Something else"));
    Foo2.Put_Line (Item => Foo1.Grid_Type' ("Something else"));

                                   -- Adam



  reply	other threads:[~2013-09-24 18:43 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-09-24 17:38 Ambiguous expressions - Help! Mike H
2013-09-24 18:15 ` Eryndlia Mavourneen
2013-09-24 18:43   ` Adam Beneschan [this message]
2013-09-24 20:34     ` Robert A Duff
2013-09-24 18:37 ` Jeffrey Carter
2013-09-24 21:08 ` Georg Bauhaus
2013-09-25  7:14 ` Mike H
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox