comp.lang.ada
 help / color / mirror / Atom feed
From: Adam Beneschan <adam@irvine.com>
Subject: Re: Address and bit mask
Date: Tue, 30 Aug 2011 12:31:55 -0700 (PDT)
Date: 2011-08-30T12:31:55-07:00	[thread overview]
Message-ID: <3756bc0c-d938-4b45-baa1-b80e59d58055@a10g2000prn.googlegroups.com> (raw)
In-Reply-To: 4e5d139f$0$6575$9b4e6d93@newsspool3.arcor-online.net

On Aug 30, 9:45 am, Georg Bauhaus <rm.dash-bauh...@futureapps.de>
wrote:

> > In Ada, I found nothing similar and even finding howto do a kind of
> > 'printf("%x"...)'... hum, sorry... displaying an Integer in hexa, is
> > difficult.
>
> How do you print an int in duodecimal (base 12) in C? :-)
>
> Base 16 and others in Ada:
>
> with Ada.Text_IO;
>
> procedure Int_Based is
>    use Ada;
>
>    package Duodec_IO is
>       new Text_IO.Integer_IO (Natural);
>
>    X : Natural := 123;
> begin
>    Duodec_IO.Put (X, Base => 3);
>    Duodec_IO.Put (X, Base => 8);
>    Duodec_IO.Put (X, Base => 10);
>    Duodec_IO.Put (X, Base => 12);
>    Duodec_IO.Put (X, Base => 16);
>    Text_IO.New_Line;
> end Int_Based;

I realize you had a smiley in there, but showing how easy it is to do
something that nobody is likely to want to do in a million
(12#402854#) years isn't really the best advertisement we can come up
with for the language.

I actually think Ada has a bit of a weakness in this regard.  The
ability to output and/or create strings that have data interpolated in
them is useful, but doing so with Ada is somewhat clunky.  Ada does
provide a string concatenation function, which C doesn't have, and
that could help, except that (1) there's no *function* defined in Ada
that returns the image of an integer in a given base (and if there
were, I'd want it to have options to control whether the 16#...# were
present or not, whether letters were in upper or lower case, and
whether and how far we add leading zeroes), and (2) the 'Image
attribute function on integer types has the annoying problem of the
extra space at the front of nonnegative integers.  With those fixed,
it would eliminate an objection I'm sure other C programmers trying to
use Ada have run into.

Of course, C's printf() is really a terrible solution to the problem,
mainly because you have to specify in the format string what the
length of the integer data is (short, long, long long), and if you get
it wrong and the format specifiers don't match the variable
arguments---woe, woe, woe.  (And that problem is still minor compared
to what happens if you get the length wrong in scanf(), as I've done
in the past.)

                                         -- Adam



  reply	other threads:[~2011-08-30 19:31 UTC|newest]

Thread overview: 64+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-08-29 15:46 Address and bit mask milouz
2011-08-29 16:06 ` Martin
2011-08-29 16:33   ` milouz
2011-08-29 17:47     ` Dmitry A. Kazakov
2011-08-29 17:54     ` Martin
2011-08-29 18:46     ` tmoran
2011-08-29 19:41 ` Ludovic Brenta
2011-08-29 19:54   ` Adam Beneschan
2011-08-30  9:14     ` milouz
2011-08-30 10:34       ` Ludovic Brenta
2011-08-30 10:58         ` Ludovic Brenta
2011-08-30 12:44           ` Georg Bauhaus
2011-08-30 14:04             ` Dmitry A. Kazakov
2011-08-30 16:12               ` Georg Bauhaus
2011-08-30 16:59                 ` Dmitry A. Kazakov
2011-08-30 14:52         ` Adam Beneschan
2011-08-30 10:40       ` Simon Wright
2011-08-30 10:44         ` Simon Wright
2011-08-30 15:20         ` tmoran
2011-08-30 16:08           ` milouz
2011-08-30 16:45             ` Georg Bauhaus
2011-08-30 19:31               ` Adam Beneschan [this message]
2011-08-30 19:56                 ` Dmitry A. Kazakov
2011-08-31  6:16                   ` The simple Image issue (was: Address and bit mask) Georg Bauhaus
2011-08-31 14:44                     ` The simple Image issue Dmitry A. Kazakov
2011-08-31 15:36                       ` Georg Bauhaus
2011-08-31 15:53                         ` Dmitry A. Kazakov
2011-08-31 16:23                           ` Georg Bauhaus
2011-08-31 16:27                             ` Dmitry A. Kazakov
2011-08-31 16:30                               ` Georg Bauhaus
2011-08-31 16:50                                 ` Dmitry A. Kazakov
2011-08-31 20:41                                   ` Georg Bauhaus
2011-08-31 21:17                                     ` Robert A Duff
2011-09-01  7:36                                       ` Dmitry A. Kazakov
2011-09-01  7:46                                     ` Dmitry A. Kazakov
2011-09-01  9:50                                       ` Overloading parentheses and type expectations (was: The simple Image issue) Georg Bauhaus
2011-09-02  7:54                                         ` Overloading parentheses and type expectations Dmitry A. Kazakov
2011-09-02 10:37                                           ` Georg Bauhaus
2011-09-02 12:40                                             ` Dmitry A. Kazakov
2011-09-02 16:08                                               ` Georg Bauhaus
2011-09-02 17:29                                                 ` Dmitry A. Kazakov
2011-08-31 15:53                     ` The simple Image issue Hyman Rosen
2011-08-31 16:07                       ` Dmitry A. Kazakov
2011-08-31 16:08                       ` Simon Wright
2011-08-31 16:26                         ` Dmitry A. Kazakov
2011-08-31 16:25                       ` Georg Bauhaus
2011-08-31 16:30                         ` Hyman Rosen
2011-08-31 16:34                           ` Georg Bauhaus
2011-08-31 16:43                             ` Adam Beneschan
2011-08-31 21:58                               ` Georg Bauhaus
2011-09-01  7:59                                 ` Dmitry A. Kazakov
2011-08-31 16:08                     ` The simple Image issue (was: Address and bit mask) Adam Beneschan
2011-08-31 16:53                       ` The simple Image issue Simon Wright
2011-08-31 17:02                         ` Hyman Rosen
2011-08-31 20:33                       ` Georg Bauhaus
2011-08-30 19:37             ` Address and bit mask Martin
2011-08-30 16:32           ` Simon Wright
2011-08-31  7:55             ` Ludovic Brenta
2011-08-30 12:35       ` Georg Bauhaus
2011-08-30 13:03       ` Georg Bauhaus
2011-08-30 15:14       ` Adam Beneschan
2011-08-30 15:59         ` Adam Beneschan
2011-08-31  7:45         ` milouz
2011-08-31  8:35           ` Ludovic Brenta
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox