From: Victor Porton <porton@narod.ru>
Subject: Re: 'Size hack for enumerated types
Date: Sun, 06 Jul 2014 01:23:07 +0300
Date: 2014-07-06T01:23:07+03:00 [thread overview]
Message-ID: <lp9tsc$7aq$1@speranza.aioe.org> (raw)
In-Reply-To: lp9tj0$6ii$1@speranza.aioe.org
Victor Porton wrote:
> I tried to implement it in a memory savvy way. But GNAT does not compile
> it. It would be good if a future version of Ada supported it.
>
> -- rds.ads
> package RDF is
> end RDF;
>
> -- rdf-auxilary.ads
> with Interfaces.C;
>
> package RDF.Auxilary is
>
> generic
> type Enum_Type is range <>;
> package Convert_Enum is
> function To_C(Argument: Enum_Type) return Interfaces.C.int;
> function From_C(Argument: Interfaces.C.int) return Enum_Type;
> end;
>
> end RDF.Auxilary;
>
> -- rdf-auxilary.adb
> with Ada.Unchecked_Conversion;
>
> package body RDF.Auxilary is
>
> package body Convert_Enum is
>
> type Small is mod 2**(Enum_Type'Size);
Sorry, need also multiply with byte size in bits. BTW, how to get it?
> function To_C_Internal is
> new Ada.Unchecked_Conversion (Source => Enum_Type, Target =>
> Small);
>
> function From_C_Internal is
> new Ada.Unchecked_Conversion (Source => Small, Target =>
> Enum_Type);
>
> function To_C(Argument: Enum_Type) return Interfaces.C.int is
> begin
> return Interfaces.C.int(To_C_Internal(Argument));
> end;
>
> function From_C(Argument: Interfaces.C.int) return Enum_Type is
> begin
> return From_C_Internal(Small(Argument));
> end;
>
> end;
>
> end RDF.Auxilary;
>
> gnatmake -q -c -gnatc -u -P/home/porton/Projects/redland-
> bindings/ada/test.gpr -XRUNTIME=full -XMODE=Install rdf-auxilary.adb
> rdf-auxilary.adb:7:25: non-static expression used for modular type bound
> rdf-auxilary.adb:7:38: size attribute is only static for static scalar
> type (RM 4.9(7,8))
> gnatmake:
> "/home/porton/Projects/redland-bindings/ada/src/rdf-auxilary.adb"
> compilation error
>
>
--
Victor Porton - http://portonvictor.org
next prev parent reply other threads:[~2014-07-05 22:23 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-07-05 20:32 'Size hack for enumerated types Victor Porton
2014-07-05 21:47 ` Simon Wright
2014-07-05 22:11 ` Victor Porton
2014-07-05 22:18 ` Victor Porton
2014-07-05 22:23 ` Victor Porton [this message]
2014-07-06 16:25 ` Victor Porton
2014-07-06 20:59 ` Simon Wright
2014-07-06 23:01 ` Victor Porton
2014-07-06 23:30 ` Jeffrey Carter
2014-07-07 16:00 ` Victor Porton
2014-07-07 17:12 ` Simon Wright
2014-07-07 20:23 ` Victor Porton
2014-07-08 7:04 ` Simon Wright
2014-07-08 10:17 ` sbelmont700
2014-07-08 14:53 ` Dan'l Miller
2014-07-08 20:56 ` Randy Brukardt
2014-07-08 22:26 ` Dan'l Miller
2014-07-08 23:18 ` Jeffrey Carter
2014-07-08 9:43 ` AdaMagica
2014-07-08 13:52 ` Victor Porton
2014-07-08 15:02 ` Simon Wright
2014-07-07 7:45 ` Simon Wright
2014-07-06 7:22 ` Simon Wright
2014-07-06 13:21 ` sbelmont700
2014-07-06 16:16 ` Victor Porton
2014-07-06 17:52 ` sbelmont700
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox