TEAM-ADA Archives

Team Ada: Ada Programming Language Advocacy

TEAM-ADA@LISTSERV.ACM.ORG

Options: Use Forum View

Use Monospaced Font
Show HTML Part by Default
Show All Mail Headers

Message: [<< First] [< Prev] [Next >] [Last >>]
Topic: [<< First] [< Prev] [Next >] [Last >>]
Author: [<< First] [< Prev] [Next >] [Last >>]

Print Reply
Subject:
From:
"Krishna, Buska (IE10)" <[log in to unmask]>
Reply To:
Krishna, Buska (IE10)
Date:
Fri, 31 Aug 2001 11:17:28 +0530
Content-Type:
text/plain
Parts/Attachments:
text/plain (46 lines)
Hi all,
        I have written a piece of code, in which I am using an enumeartion
type. I am assigning some values to the enumeration items by using for
statement. I want to refer the assigned vales using the enumeration items.
That is as shown in the code I wanna refer the values 16#10# using the enum
item "one", 16#20# using "two" etc. Is there any ways to do this? My aim is
to assign some values to the enumeration type and use those values in the
place of the enum items just like in C.

Ada code:

with Ada.Text_Io;
use Ada.Text_Io;
with Ada.Integer_Text_IO;
use Ada.Integer_Text_IO;

procedure Test is
   type Enum is
         (One,
          Two,
          Three);
   for Enum use
      (
      One   => 16#10#,
      Two   => 16#20#,
      Three => 16#30#);
begin
   Put( Enum'Pos (Three));
   New_Line;
   Put_Line (Enum'Image (Three));
end Test;

in C:
enum {
one = Ox10,
two =Ox20,
three =0x30
} ;

later I can use "one" to refer its value and son on.

Could any body clarify me, if there is any way to do this.

Thanx in advance.
Krishna

ATOM RSS1 RSS2