comp.lang.ada
 help / color / mirror / Atom feed
* Semantics of 'Image and 'Wide_Image on wide enumerations
@ 2010-12-03 20:25 Michael R
  2010-12-03 20:56 ` Adam Beneschan
  0 siblings, 1 reply; 4+ messages in thread
From: Michael R @ 2010-12-03 20:25 UTC (permalink / raw)


Hi Folks,

I'm trying to figure out how to get wide enumeration types to generate
wide images of the values and am not getting results I would expect.
Using the simple 'Image, e.g.,

with Ada.Text_IO;
procedure WEnum1 is
   use Ada.Text_IO;
   type Greek is (α, β, γ);
begin
   Put_Line ("Alpha is " & Greek'Image (α));
end WEnum

Gives, (possibly encoded?):

$ gnatmake -gnat05 -gnatW8 wenum1.adb
gcc -c -gnat05 -gnatW8 wenum1.adb
gnatbind -x wenum1.ali
gnatlink wenum1.ali
$ ./wenum1
Alpha is Α[]

Using 'Wide_Image gives something more reasonable but not the actual
wide characters:

with Ada.Wide_Text_IO;
procedure WEnum2 is
   use Ada.Wide_Text_IO;
   type Greek is (α, β, γ);
begin
   Put_Line ("Alpha is " & Greek'Wide_Image (α));
end WEnum2;

$ gnatmake -gnat05 -gnatW8 wenum2.adb
gcc -c -gnat05 -gnatW8 wenum2.adb
gnatbind -x wenum2.ali
gnatlink wenum2.ali
$ ./wenum2
Alpha is Α

Is this the expected behaviour?  The RM doesn't really say anything
much about such wide values.

Take care,
Michael.



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Semantics of 'Image and 'Wide_Image on wide enumerations
  2010-12-03 20:25 Semantics of 'Image and 'Wide_Image on wide enumerations Michael R
@ 2010-12-03 20:56 ` Adam Beneschan
  2010-12-03 21:15   ` Michael R
  2010-12-03 21:17   ` Adam Beneschan
  0 siblings, 2 replies; 4+ messages in thread
From: Adam Beneschan @ 2010-12-03 20:56 UTC (permalink / raw)


On Dec 3, 12:25 pm, Michael R <mich...@zanyblue.com> wrote:
> Hi Folks,
>
> I'm trying to figure out how to get wide enumeration types to generate
> wide images of the values and am not getting results I would expect.
> Using the simple 'Image, e.g.,
>
> with Ada.Text_IO;
> procedure WEnum1 is
>    use Ada.Text_IO;
>    type Greek is (α, β, γ);
> begin
>    Put_Line ("Alpha is " & Greek'Image (α));
> end WEnum
>
> Gives, (possibly encoded?):
>
> $ gnatmake -gnat05 -gnatW8 wenum1.adb
> gcc -c -gnat05 -gnatW8 wenum1.adb
> gnatbind -x wenum1.ali
> gnatlink wenum1.ali
> $ ./wenum1
> Alpha is Α[]
>
> Using 'Wide_Image gives something more reasonable but not the actual
> wide characters:
>
> with Ada.Wide_Text_IO;
> procedure WEnum2 is
>    use Ada.Wide_Text_IO;
>    type Greek is (α, β, γ);
> begin
>    Put_Line ("Alpha is " & Greek'Wide_Image (α));
> end WEnum2;
>
> $ gnatmake -gnat05 -gnatW8 wenum2.adb
> gcc -c -gnat05 -gnatW8 wenum2.adb
> gnatbind -x wenum2.ali
> gnatlink wenum2.ali
> $ ./wenum2
> Alpha is Α
>
> Is this the expected behaviour?

I think that 'Image, 'Wide_Image, and 'Wide_Wide_Image of enumerations
(other than character literals) put the output in upper case, where
there is an upper case.  So what you're seeing is an upper-case alpha,
which looks just like an A.

                        -- Adam




^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Semantics of 'Image and 'Wide_Image on wide enumerations
  2010-12-03 20:56 ` Adam Beneschan
@ 2010-12-03 21:15   ` Michael R
  2010-12-03 21:17   ` Adam Beneschan
  1 sibling, 0 replies; 4+ messages in thread
From: Michael R @ 2010-12-03 21:15 UTC (permalink / raw)


On Dec 3, 12:56 pm, Adam Beneschan <a...@irvine.com> wrote:
> On Dec 3, 12:25 pm, Michael R <mich...@zanyblue.com> wrote:
>
>
>
> > Hi Folks,
>
> > I'm trying to figure out how to get wide enumeration types to generate
> > wide images of the values and am not getting results I would expect.
> > Using the simple 'Image, e.g.,
>
> > with Ada.Text_IO;
> > procedure WEnum1 is
> >    use Ada.Text_IO;
> >    type Greek is (α, β, γ);
> > begin
> >    Put_Line ("Alpha is " & Greek'Image (α));
> > end WEnum
>
> > Gives, (possibly encoded?):
>
> > $ gnatmake -gnat05 -gnatW8 wenum1.adb
> > gcc -c -gnat05 -gnatW8 wenum1.adb
> > gnatbind -x wenum1.ali
> > gnatlink wenum1.ali
> > $ ./wenum1
> > Alpha is Α[]
>
> > Using 'Wide_Image gives something more reasonable but not the actual
> > wide characters:
>
> > with Ada.Wide_Text_IO;
> > procedure WEnum2 is
> >    use Ada.Wide_Text_IO;
> >    type Greek is (α, β, γ);
> > begin
> >    Put_Line ("Alpha is " & Greek'Wide_Image (α));
> > end WEnum2;
>
> > $ gnatmake -gnat05 -gnatW8 wenum2.adb
> > gcc -c -gnat05 -gnatW8 wenum2.adb
> > gnatbind -x wenum2.ali
> > gnatlink wenum2.ali
> > $ ./wenum2
> > Alpha is Α
>
> > Is this the expected behaviour?
>
> I think that 'Image, 'Wide_Image, and 'Wide_Wide_Image of enumerations
> (other than character literals) put the output in upper case, where
> there is an upper case.  So what you're seeing is an upper-case alpha,
> which looks just like an A.
>
>                         -- Adam

Hi,

Confirmed, I just didn't go far enough (it was outputting uppercase):

with Ada.Wide_Text_IO;
procedure WEnum2 is
   use Ada.Wide_Text_IO;
   type Greek is (α, β, γ);
begin
   for Letter in Greek'Range loop
      Put_Line (Greek'Wide_Image (Letter));
   end loop;
end WEnum2;

Gives,

$ gnatmake -gnat05 -gnatW8 wenum2.adb
gcc-4.4 -c -gnat05 -gnatW8 wenum2.adb
gnatbind -x wenum2.ali
gnatlink wenum2.ali
$ ./wenum2
Α
Β
Γ

Take care,
Michael.




^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Semantics of 'Image and 'Wide_Image on wide enumerations
  2010-12-03 20:56 ` Adam Beneschan
  2010-12-03 21:15   ` Michael R
@ 2010-12-03 21:17   ` Adam Beneschan
  1 sibling, 0 replies; 4+ messages in thread
From: Adam Beneschan @ 2010-12-03 21:17 UTC (permalink / raw)


On Dec 3, 12:56 pm, Adam Beneschan <a...@irvine.com> wrote:
> On Dec 3, 12:25 pm, Michael R <mich...@zanyblue.com> wrote:
>
>
>
>
>
> > Hi Folks,
>
> > I'm trying to figure out how to get wide enumeration types to generate
> > wide images of the values and am not getting results I would expect.
> > Using the simple 'Image, e.g.,
>
> > with Ada.Text_IO;
> > procedure WEnum1 is
> >    use Ada.Text_IO;
> >    type Greek is (α, β, γ);
> > begin
> >    Put_Line ("Alpha is " & Greek'Image (α));
> > end WEnum
>
> > Gives, (possibly encoded?):
>
> > $ gnatmake -gnat05 -gnatW8 wenum1.adb
> > gcc -c -gnat05 -gnatW8 wenum1.adb
> > gnatbind -x wenum1.ali
> > gnatlink wenum1.ali
> > $ ./wenum1
> > Alpha is Α[]
>
> > Using 'Wide_Image gives something more reasonable but not the actual
> > wide characters:
>
> > with Ada.Wide_Text_IO;
> > procedure WEnum2 is
> >    use Ada.Wide_Text_IO;
> >    type Greek is (α, β, γ);
> > begin
> >    Put_Line ("Alpha is " & Greek'Wide_Image (α));
> > end WEnum2;
>
> > $ gnatmake -gnat05 -gnatW8 wenum2.adb
> > gcc -c -gnat05 -gnatW8 wenum2.adb
> > gnatbind -x wenum2.ali
> > gnatlink wenum2.ali
> > $ ./wenum2
> > Alpha is Α
>
> > Is this the expected behaviour?
>
> I think that 'Image, 'Wide_Image, and 'Wide_Wide_Image of enumerations
> (other than character literals) put the output in upper case, where
> there is an upper case.  So what you're seeing is an upper-case alpha,
> which looks just like an A.

I didn't answer all parts of this...  For 'Image, if there are
characters in the image that aren't in the Character type, the result
is implementation-defined.  I don't know if the actual result you're
getting from GNAT has some meaning or is just random or is a bug;
you'd have to ask them.  But yes, the RM here doesn't say specifically
what you should expect, except that it's as least as long as the
'Wide_Wide_Image would be.

The relevant RM sections here are in 3.5, paragraphs 27.5 and 37.

                       -- Adam



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2010-12-03 21:17 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-12-03 20:25 Semantics of 'Image and 'Wide_Image on wide enumerations Michael R
2010-12-03 20:56 ` Adam Beneschan
2010-12-03 21:15   ` Michael R
2010-12-03 21:17   ` Adam Beneschan

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