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: border2.nntp.dca.giganews.com!nntp.giganews.com!border1.nntp.hkg.giganews.com!news.netfront.net!goblin2!goblin.stu.neva.ru!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:23:07 +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: number.nntp.dca.giganews.com comp.lang.ada:187389 Date: 2014-07-06T01:23:07+03:00 List-Id: 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