comp.lang.ada
 help / color / mirror / Atom feed
From: jdla@my-deja.com
Subject: Re: Newbie question : types , representation
Date: 1999/08/24
Date: 1999-08-24T00:00:00+00:00	[thread overview]
Message-ID: <7ptsgn$nvp$1@nnrp1.deja.com> (raw)
In-Reply-To: 7ppdon$j3p$1@nnrp1.deja.com

In article <7ppdon$j3p$1@nnrp1.deja.com>,
  Robert Dewar <robert_dewar@my-deja.com> wrote:
> In article <37BFC251.601ADF8F@village.uunet.be>,
>   Jos De Laender <De_Laender-De_Winter@village.uunet.be> wrote:
> > In C I could do it within 5 minutes.
>
> Probably by making unwarranted assumptions :-)

For sure. But I don't think I would have much to assume except for the
char being 8 bits.
The remainder of operations I could do on that level.
Of course I would also have to include some #ifdef 's ;-)

>
> > It would involve some bitmanipulation (shifting , anding ,
> > oring ) on
> > the character itself and then outputting. That's it.
> >
> > However, what's unclear is how to do this in ADA types : A
> > character
> > cannot be bit manipulated , and so needs some explicit
> > translation to a
> > 'byte' or something.
> > How is this usually done ? I would guess to use a modular type
> 2**8 ? If
> > I declare such a type , and I want a byte , is this guaranteed
> by 2**8
> > or do I have explicitly  to attribute it with a 'for Byte'size
> use 8' ?
>
> Is char guaranteed to be 8 bits in C, answer no ...

No, I know.

The point is however that when for a compiler/architecture it is 8 bits,
it would be 8 bits for all instances of a char , isn't it ?

Does this same property hold for modular types like 2**8 , i.e. is it
allowed that one instance takes 8 bits and another 16 bits , due to
other optimization ?

How does the use 'size influence this ?

>
> > Also I will need some kind of assignment to that modular type,
> say aVar
> > := 2#00000011#. This will assign the value 3 to aVar ? Is this
> > guaranteed to have that bit pattern ?
>
> nope, and of course there is no such guarantee in C either

Again I know. But in C I would start from characters with known
representation (i.e. ascii) and do bitlevel operations. I would not need
the assignment on that level.

>
> > Or could I imagine a (probably
> > exotic) machine on which 3 is represented with another bit
> pattern ?
>
> If you want to imagine such machines, your imagination is
> equally relevant in C or Ada.

For me this isn't _that_ imaginery. I constructed already (small)
processing units in which the representation was quite different for
power reasons. Luckily I didn't have to construct compilers for it ...

>
> > Does ADA guarantee ?
> > If I output aVar with a write function , is the bitpattern
> guaranteed ?
>
> nope, and neither does C
>
> > Thanks for all clarifications.
>
> Bottom line here: Don't get carried away by the formalism here.
> Write reasonable code with reasonable assumptions, as you would
> in C. Your low level bit twiddling stuff may be a target
> dependent, at least from a theoretical point of view, but that's
> not a terrible crime (and certainly no worse a crime in Ada
> than in C :-)

Thanks for the answer. ADA has as least the advantage that it makes you
_think_ about those issues. But I didn't see however too much of
practical answers how to do, in a ADA way and without spoiling to much
processor cycles in converting hence and back. But I'll find out for
sure ...

>
> Sent via Deja.com http://www.deja.com/
> Share what you know. Learn what you don't.
>


Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.




  parent reply	other threads:[~1999-08-24  0:00 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1999-08-22  0:00 Newbie question : types , representation Jos De Laender
1999-08-22  0:00 ` Martin Dowie
1999-08-22  0:00 ` Robert Dewar
1999-08-23  0:00   ` Wolfgang Jeltsch
1999-08-24  0:00     ` tmoran
1999-08-24  0:00   ` jdla [this message]
1999-08-24  0:00     ` Matthew Heaney
1999-08-24  0:00       ` Jos De Laender
1999-08-24  0:00         ` Brian Rogoff
1999-08-25  0:00           ` Jos De Laender
1999-08-22  0:00 ` Wilhelm Spickermann
1999-08-23  0:00   ` Martin C. Carlisle
1999-08-23  0:00   ` Simon Wright
     [not found] ` <37C621F3.C6C0DC3A@acenet.com.au>
1999-08-27  0:00   ` David C. Hoos, Sr.
1999-08-27  0:00   ` tmoran
1999-08-27  0:00     ` Florian Weimer
replies disabled

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