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.3 required=5.0 tests=BAYES_00,INVALID_MSGID, MSGID_RANDY autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,7844279822ce7c28 X-Google-Attributes: gid103376,public From: Robert Dewar Subject: Re: Newbie question : types , representation Date: 1999/08/22 Message-ID: <7ppdon$j3p$1@nnrp1.deja.com>#1/1 X-Deja-AN: 515846455 References: <37BFC251.601ADF8F@village.uunet.be> X-Http-Proxy: 1.0 x34.deja.com:80 (Squid/1.1.22) for client 166.72.71.31 Organization: Deja.com - Share what you know. Learn what you don't. X-Article-Creation-Date: Sun Aug 22 17:58:51 1999 GMT X-MyDeja-Info: XMYDJUIDrobert_dewar Newsgroups: comp.lang.ada X-Http-User-Agent: Mozilla/4.04 [en] (OS/2; I) Date: 1999-08-22T00:00:00+00:00 List-Id: In article <37BFC251.601ADF8F@village.uunet.be>, Jos De Laender wrote: > In C I could do it within 5 minutes. Probably by making unwarranted assumptions :-) > It would involve some bitmanipulation (shifting , anding , > oring ) on > the character itself and then outputting. That's it. > > However, what's unclear is how to do this in ADA types : A > character > cannot be bit manipulated , and so needs some explicit > translation to a > 'byte' or something. > How is this usually done ? I would guess to use a modular type 2**8 ? If > I declare such a type , and I want a byte , is this guaranteed by 2**8 > or do I have explicitly to attribute it with a 'for Byte'size use 8' ? Is char guaranteed to be 8 bits in C, answer no ... > Also I will need some kind of assignment to that modular type, say aVar > := 2#00000011#. This will assign the value 3 to aVar ? Is this > guaranteed to have that bit pattern ? nope, and of course there is no such guarantee in C either > Or could I imagine a (probably > exotic) machine on which 3 is represented with another bit pattern ? If you want to imagine such machines, your imagination is equally relevant in C or Ada. > Does ADA guarantee ? > If I output aVar with a write function , is the bitpattern guaranteed ? nope, and neither does C > Thanks for all clarifications. Bottom line here: Don't get carried away by the formalism here. Write reasonable code with reasonable assumptions, as you would in C. Your low level bit twiddling stuff may be a target dependent, at least from a theoretical point of view, but that's not a terrible crime (and certainly no worse a crime in Ada than in C :-) Sent via Deja.com http://www.deja.com/ Share what you know. Learn what you don't.