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,5c7cd5f5eb536a38,start X-Google-Attributes: gid103376,public From: G Subject: to type or subtype ? (novice question, three parts) Date: 2000/02/15 Message-ID: <38A94303.125C337F@interact.net.au>#1/1 X-Deja-AN: 586092194 Content-Transfer-Encoding: 7bit X-Accept-Language: en Content-Type: text/plain; charset=us-ascii X-Complaints-To: abuse@interact.net.au X-Trace: news.interact.net.au 950616900 203.56.111.71 (Tue, 15 Feb 2000 23:15:00 EST) Organization: BDF MIME-Version: 1.0 NNTP-Posting-Date: Tue, 15 Feb 2000 23:15:00 EST Newsgroups: comp.lang.ada Date: 2000-02-15T00:00:00+00:00 List-Id: Hi all, and thanks so much for all your help. :-) I hope this is all relevant to the newsgroup topic. There are not as many diverse sources about Ada as there are other languages, so it is sometimes difficult to get helpful information. I try to get it straight from the horse's mouth, as it were... There are three questions in this message. One is about types and subtypes. Two is about signed modular integers. Three is about a very little bit of MIL-STD-1553B. ------------------------------------------ ------------------------------------------ 1: Ok, something I don't understand - when should you make a new type, say : type widget is new integer; or, say : subtype widget is integer; - when they are both integers. That is - what difference does it make with what you can do with/to the type ? I have been receiving numerous mysterious errors in (yes, trivial) code I write relating to types and subtypes and I am certain that this is due to not knowing the range of relevance/application of each. (Love the LRM as I do *choke*, it doesn't explain in language I understand :) "A subtype of a given type is a combination of the type, a constraint on values of the type, and certain attributes specific to the subtype. The given type is called the type of the subtype. Similarly, the associated constraint is called the constraint of the subtype. The set of values of a subtype consists of the values of its type that satisfy its constraint. Such values belong to the subtype." -- LRM 3.2(paragraph 8) So, lets say, in a fever of unambiguous autodidactic ambition I desire to manipulate low level constructs with Boolean logic (so that I can test some general principles from the Art of Assembly with Ada to keep it all where I can understand it) I will need need some basic types to work with, do I write something like: type byte is mod 2*8; subtype bit_mask is byte; -- or something like: type byte is mod 2*8; type bit_mask is new byte; -- or does it make more sense to say something like: type byte is mod 2*8; my_byte : byte; bit_mask : byte; -- there just seem to be so many (& more) combinations, I don't understand which is most sensible/efficient. I suspect it might depend on the context. It seems to me that all of these (even displacing types into variables) allow similar values to be manipulated. Would you use something like "type bit_mask is new byte;" only when you had a helluva lot of bit_masks to work with ? Would I better to make some sort of tagged type byte and then derive relevant masks from that ? If that is possible. ------------------------------------------------------------ ------------------------------------------------------------ 2: Modular integers and the interfaces.unsigned_32 types - it appears as though (after some compiler experimentation) that modular integers are always going to be signed and should have to be the only type I can use for signed bytes, words, etc. no ? yes ? maybe ? (I am trying to use Ada to experiment & learn with concepts I get from all over the place in technical manuals, tutorials, etc. I have found interfaces.unsigned_xx to allow values in the range 2*3 .. 2*6. ) I use GNAT 3.11. ------------------------------------------------ ------------------------------------------------ 3. In an implementation of MIL-STD-1553B I have read, there is a declaration: type Bit_Numbers is range 0 .. 15; - I am wondering why anyone would want to work with individual bits (that is what I interpret that as for) in this way, because you can alter their values with logical bit_masks. I was reading that the 80x86 works more efficiently with bytes than with the smaller bits. Would you want to work with individual bits in some situations because some embedded/special-purpose computers may have different architectures which make it relevant to manipulate individual bits in this manner ? ------- ------- - I am struggling to understand, sorry if this is irrelevant. -- GM Wallace. BDF --