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 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,1514d4f994aed7aa X-Google-Attributes: gid103376,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news2.google.com!newsfeed2.dallas1.level3.net!news.level3.com!newsfeed-00.mathworks.com!nntp.TheWorld.com!not-for-mail From: Robert A Duff Newsgroups: comp.lang.ada Subject: Re: generic function and overloading Date: Thu, 18 Oct 2007 17:23:24 -0400 Organization: The World Public Access UNIX, Brookline, MA Message-ID: References: <1192688972.967825.31130@t8g2000prg.googlegroups.com> NNTP-Posting-Host: shell01.theworld.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: pcls4.std.com 1192742616 8321 192.74.137.71 (18 Oct 2007 21:23:36 GMT) X-Complaints-To: abuse@TheWorld.com NNTP-Posting-Date: Thu, 18 Oct 2007 21:23:36 +0000 (UTC) User-Agent: Gnus/5.1008 (Gnus v5.10.8) Emacs/21.3 (irix) Cancel-Lock: sha1:HQqjKCFTfNWeaUTl/Hfztrl24Oo= Xref: g2news2.google.com comp.lang.ada:2487 Date: 2007-10-18T17:23:24-04:00 List-Id: Simon Wright writes: > Robert A Duff writes: > >> But do you really want to do arithmetic on these types, >> as well as setting/clearing bits? If all you want to >> do is set/clear bits, you might want to consider using >> a packed array of Boolean. Then to set the Nth bit you >> can say: >> >> X (N) := True; >> >> Alternatively, a packed array of type Bit, where: >> >> type Bit is range 0..1; >> >> If the individual bit numbers have some specific meaning, >> the index type could be an enumeration type. > > Will give surprising results on a big-endian machine. Only if you're doing something that exposes endianness. Endianness should be completely invisible to most code. (E.g., if you set the N'th bit of an array of Boolean, and get the N'th bit, you get back what you set. The same is true with masking modular integers.) >... At least code > using shifts and masks is portable if gruesome Well, it can be portable, but you can still get into endianness trouble if you do things like splitting the integer into individual bytes (e.g. to transmit them across a network). >... -- and no more gruesome > than code I've written which says > > type Unrepresented is .. > Internal : Unrepresented; > ... > > if System.Default_Bit_Order = System.High_Order_First then > declare > type Represented is .. > for Represented use .. > -- record rep with big-endian usage > External : constant Represented := Internal; Do you mean "type Represented is new Unrepresented;"? Then you need a type conversion in the line above. Nitpick: I'd use a case statement rather than an if statement, here. > begin > Output (External); > end; > else > -- equivalent for l-e - Bob