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 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: Brian Rogoff Subject: Re: Newbie question : types , representation Date: 1999/08/24 Message-ID: #1/1 X-Deja-AN: 516855795 References: <37BFC251.601ADF8F@village.uunet.be> <7ppdon$j3p$1@nnrp1.deja.com> <7ptsgn$nvp$1@nnrp1.deja.com> <37c2d548@news1.us.ibm.net> <37C2E8BE.40461448@village.uunet.be> Content-Type: TEXT/PLAIN; charset=US-ASCII X-Trace: nntp1.ba.best.com 935552070 224 bpr@206.184.139.136 MIME-Version: 1.0 Newsgroups: comp.lang.ada Date: 1999-08-24T00:00:00+00:00 List-Id: On Tue, 24 Aug 1999, Jos De Laender wrote: > What I do know that in C, I can do all of my operations (shifting, > anding ..) on chars. In Ada (we always mean Ada 95 here when we say Ada, a situation unlike the VHDL world ;-) the package Interfaces contains the Shift_Left, Shift_Right, and other operations you're looking for, as well as types like Unsigned_8, Unsigned_16, etc. These are probably what you're looking for. I rather wish there were operators (<<, >>) for this, as in C, but it is not a problem, just my syntactic preference. I won't even start talking about <<= :-) > It's ugly in the sense that I'm mixing really semantics of chars and > bytes and integers and whatever. But on compiler output I can expect a > fairly optimal implementation. I guess I don't find it (C) that ugly here, but my tastes are my own. C is a very low level language compared to Ada, so it is to be expected that it would be this way. C declaration syntax is ugly IMO. > In ADA , I think (but this was part of the question) , I have to go > through some tables and through some conversion functions. Although it > is not necessarily so , there is at least the increased risk of less > optimal implementation, because the compiler has to find out those > things. I didn't say this is not possible, I asked how one could write > it without having this risk. If you know that characters are the same size as your "byte" type, be it an Interfaces.Unsigned_8 or a System.Storage_Element then it should be OK to use Unchecked_Conversion if you're worried about the overhead of a conversion function, but I really can't imagine any overhead even from a safe type conversion if you turn checking off, which you really must do if you want to compare with C. I don't understand why you think there is some table lookup involved. Part of the problem with C and Ada comparisons is that every C operation is unchecked, whereas in Ada everything is checked by default. You have to know enough about your Ada compiler to turn off those checks when doing the performance comparisons. -- Brian