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,f3514db0a21f9b44 X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,UTF8 Path: g2news2.google.com!news1.google.com!npeer02.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!post02.iad.highwinds-media.com!news.flashnewsgroups.com-b7.4zTQh5tI3A!not-for-mail From: Stephen Leake Newsgroups: comp.lang.ada Subject: Re: Hexadecimal and stream element arrays References: <82fx2q4mbu.fsf@stephe-leake.org> Date: Wed, 21 Apr 2010 08:38:35 -0400 Message-ID: <821ve9nfp0.fsf@stephe-leake.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1.96 (windows-nt) Cancel-Lock: sha1:xFOoTvXOJmkDt5xtb7bETTRLc6c= MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Complaints-To: abuse@flashnewsgroups.com Organization: FlashNewsgroups.com X-Trace: 65b654bcef1c1e197caa708389 Xref: g2news2.google.com comp.lang.ada:11080 Date: 2010-04-21T08:38:35-04:00 List-Id: "Jeffrey R. Carter" writes: > On Apr 20, 12:25 am, Stephen Leake > wrote: >> >> generic >>    Width : Natural; >>    type Number_Type is mod <>; >> function SAL.Generic_Hex_Image (Item : in Number_Type) return String; >> --  Return a hexadecimal image of Item, padded with leading zeros to >> --  Width. If Width is too small for Item, leading digits are silently >> --  truncated. > > So if I sometimes want different widths for the same type, I have to > have multiple instantiations? Yes. But in practice, the width you want is Number_Type'Width (but assuming hexadecimal), so it's not a problem. The only problem I've encountered is the "silently truncated" part. We changed a number type to have more bits, but forgot to change the Width parameter here. There are times, such as building formatted dates, when I need a specific number of characters, and want an exception if the actual value can't be represented in that number. Then this function is not appropriate. > That doesn't seem very friendly to me. I don't see why Width couldn't > be a parameter of the function, It could; in the body, it is only used as the size of the result image string. It's just historical accident that it is a generic parameter instead. > probably defaulted to Number_Type'Width. That assumes base 10, so it would be wrong. If I made a change like this, I'd keep the generic parameter as the default width, or add a function that computes a default width assuming base 16, and use that as the default. > What do I do for signed integer images, I never need to image signed integers in hex; that's confusing. > for bases other than 16, sal-generic_binary_image.ads sal-generic_decimal_image.ads are the only ones I've ever needed. The binary image includes '_' every four digits. > and for signed integer images for bases other than 16? Never needed them. > Do I have to roll my own for these cases? Yes. It is far easier to test a small, focused routine than a large, general purpose one. > In Ada.Text_IO, a Width of zero implies the minimum width needed to > represent the value; here it's an expensive way to get a null String. > I'd prefer consistency with the standard. If this function were proposed as part of the Ada standard, that would make sense. However, it is part of SAL, which often has a different philosophy. > I haven't used SAL, but these are the kind of comments you'd probably > get from me if I did use this function. HTH. Thanks for your comments. -- -- Stephe