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=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!news1.google.com!news.glorb.com!newsgate.cistron.nl!xs4all!feeder.news-service.com!colt.net!peer-uk.news.demon.net!kibo.news.demon.net!news.demon.co.uk!demon!not-for-mail From: Simon Wright Newsgroups: comp.lang.ada Subject: Re: generic function and overloading Date: Fri, 19 Oct 2007 06:19:01 +0100 Organization: Pushface Message-ID: References: <1192688972.967825.31130@t8g2000prg.googlegroups.com> NNTP-Posting-Host: pogner.demon.co.uk Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: news.demon.co.uk 1192771139 22784 62.49.19.209 (19 Oct 2007 05:18:59 GMT) X-Complaints-To: abuse@demon.net NNTP-Posting-Date: Fri, 19 Oct 2007 05:18:59 +0000 (UTC) Cancel-Lock: sha1:2ovjEOQUmrw4YF9WCe3yOe6WGD0= User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.1 (darwin) Xref: g2news2.google.com comp.lang.ada:2493 Date: 2007-10-19T06:19:01+01:00 List-Id: Robert A Duff writes: > Simon Wright writes: > >> Robert A Duff writes: >>> 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.) As Adam said, this will likwly be hardware-related -- or, a near equivalent, dealing with a C peer, possibly over a network. >>... 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). We have used GNAT's XDR-based streams on eg Interfaces.Unsigned_32 and done the bit-twiddling afterwards (when we are reading, of course). >>... -- 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. Yes, I was writing from memory. > Nitpick: I'd use a case statement rather than an if statement, here. Is this for symmetry or in case some later Ada standard allows a third option? (I could buy the symmetry/clarity argument, good point).