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 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!news.eternal-september.org!news.eternal-september.org!feeder.eternal-september.org!aioe.org!.POSTED!not-for-mail From: Victor Porton Newsgroups: comp.lang.ada Subject: Re: 'Size hack for enumerated types Date: Sun, 06 Jul 2014 01:18:08 +0300 Organization: Aioe.org NNTP Server Message-ID: References: NNTP-Posting-Host: BISA/P8IHJbAM3ms471zeQ.user.speranza.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 7Bit X-Complaints-To: abuse@aioe.org User-Agent: KNode/4.12.4 X-Notice: Filtered by postfilter v. 0.8.2 Xref: news.eternal-september.org comp.lang.ada:20737 Date: 2014-07-06T01:18:08+03:00 List-Id: 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); 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