comp.lang.ada
 help / color / mirror / Atom feed
From: Ted Dennison <dennison@telepath.com>
Subject: Re: First time Ada has let me down
Date: Thu, 26 Oct 2000 14:36:33 GMT
Date: 2000-10-26T14:36:33+00:00	[thread overview]
Message-ID: <8t9fhh$h83$1@nnrp1.deja.com> (raw)
In-Reply-To: 8FD8A9ED5andrewloguecdcgycom@142.77.1.194

In article <8FD8A9ED5andrewloguecdcgycom@142.77.1.194>,
  nospam.andrew.logue@cdcgy.com (Shifty) wrote:
> something like this:
>
>   function Calculate_Ip_Header_Length
>              (Byte_At : in System.Address) return Integer is
>
>     Version_Length_Descriptor : Octet_Type;
>     for Version_Length_Descriptor use at Byte_At;

If you feel you *have* to do this kind of thing, I'd generally prefer to
see Byte_At unchecked_Converion'ed into an object of type "access
Octet_Type". I don't ever use "for use at" to alias things, as it
obfuscates the code. If a reader sees "Unchecked_Conversion", they have
a pretty good idea what's going on. Its a debatable point though.

>     Version_Mask : constant Integer := 2#00001111#;
>
>     -- Mask it.
>     --
>     Length : Integer := V_Bits.Bit_And (Temp, Version_Mask);

> I don't want to start a war over this, since there is _always_ a

In that case, it appears you picked an unfortunate subject name. It
seems your real problem isn't that "Ada let you down", but that an
obsolete version of Ada isn't letting you do things the exact way you'd
do them in C (at least not without resorting to compiler extensions) :-)

Of course I can name a couple of other situations where Ada 83 really is
liable to "let you down". That's why the language was revised.

> better way of doing things, but this solution seems simple and
> elegant, especially when I don't give hoot about the rest of the
> header structure.  You just pass the start address of the IP datagram
> to this function and it quickly returns the byte-length of the header.
> (assuming, of course, that Hlen contains the right value!)
>
> Thankfully Ada95 has native language support for bitwise integer
> operators.

I'd say you're pretty much on the money. Of course if you don't care
about any of the other fields, you could just as easily use a record
with only the one field you care about rep'ed, and then you wouldn't
have to worry about the masking (and it would probably be clearer to a
reader what is going on).

If it were me, I don't think I'd do it the way you're doing it. But you
can get it to work that way. If everyone did everything the way *I*
think it should be done, it'd probably be a pretty surreal world. :-)

--
T.E.D.

http://www.telepath.com/~dennison/Ted/TED.html


Sent via Deja.com http://www.deja.com/
Before you buy.



  parent reply	other threads:[~2000-10-26 14:36 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2000-10-25  3:50 First time Ada has let me down Shifty
2000-10-25  0:00 ` Ken Garlington
2000-10-25  0:00   ` Shifty
2000-10-26  4:00     ` Jeff Carter
2000-10-26 14:43       ` Ted Dennison
2000-10-26 17:55         ` tmoran
2000-10-26 17:12       ` Shifty
2000-10-27  1:00         ` Jeff Carter
2000-10-26 22:27       ` Guillaume
2000-10-26 21:49         ` Keith Thompson
2000-10-26 14:36     ` Ted Dennison [this message]
2000-10-26 17:55       ` tmoran
2000-10-26 23:08         ` Ted Dennison
2000-10-25  0:00 ` Larry Kilgallen
2000-10-25  0:00   ` Ted Dennison
2000-10-25  0:00     ` Larry Kilgallen
2000-10-25  0:00       ` Ted Dennison
2000-10-25  0:00 ` wv12
2000-10-25  0:00   ` Gautier
2000-10-25  0:00   ` Gisle Sælensminde
2000-10-25  0:00   ` Joel Seidman
2000-10-26  6:42   ` tmoran
2000-10-25  0:00 ` First time Ada has let me down (recipe) Guillaume
2000-10-26  2:45   ` Mats Weber
2000-10-25  4:44 ` First time Ada has let me down Julian Morrison
2000-10-25  4:50 ` Ted Dennison
2000-10-24  0:00   ` Keith Thompson
2000-10-26  0:00   ` Andreas Schulz
2000-10-26 18:05     ` Alejandro Villanueva
2000-10-26 21:46 ` Tucker Taft
replies disabled

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