comp.lang.ada
 help / color / mirror / Atom feed
From: dewar@cs.nyu.edu (Robert Dewar)
Subject: Re: Ada Portability... NOT!
Date: 19 Nov 1994 11:55:18 -0500
Date: 1994-11-19T11:55:18-05:00	[thread overview]
Message-ID: <3alalm$9di@gnat.cs.nyu.edu> (raw)
In-Reply-To: 199411182104.PAA04854@mail.cs.utexas.edu

It is probably a reasonable implementation choice to restrict reals to be
on a properly aligned boundary, since it is an annoying amount of fiddling
to deal with unaligned floating-point stuff, and yes, of course most 
processors *do* require floating-point values to be aligned. When you use
rep clauses you are definitely wandering into the area of implementation
dependent non-portable constructs (most appropriately, since one of the
functions of rep clauses is to deal with special target dependent
requirements).

There is certainly no *requirement* that an implementation reject these
declarations on a RISC machine, the code generator could generate the
code to fiddle around and copy the value. Is it a good idea to do this
behind the scenes? Not clear. Suppose a user just casually wrote rep
clauses to pack the data in a way that worked fine on one machine but
generated long inefficient sequences of code on another, do you want
to be allowed or stopped? Either answer is possible.

I certainly would never have written the original code, and I certainly
would never have written it expecting it to be portable. Writing portable
code in Ada does not come for free, it requires some consideration of 
what is and what is not implementation dependent, and this is especially
true of writing portable code containing rep clauses.

A more portable approach in your particular case is to read the data into
a byte stream (in Ada 9X, use a Storage_Array), and then use unchecked
conversion to convert the data to usable floating-point form. 

Isn't that interesting? The above advice says that you can make the code
*more* portable by using unchecked_conversion. Often people have a knee-jerk
reaction to avoid UC in portable code, but that's quite misinformed. Just as
a careful C programmer will use (carefully chosen) cross-type casts to
achieve portability, a careful Ada programmer can use (carefully chosen)
unchecked conversions.

Actually in Ada 9X, this sort of problem is much better handled using
streams in any case.




  reply	other threads:[~1994-11-19 16:55 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1994-11-18 21:04 Ada Portability... NOT! Capt. Britt Snodgrass
1994-11-19 16:55 ` Robert Dewar [this message]
1994-11-21  2:11   ` Carlos Perez
1994-11-21 13:17     ` Robert Dewar
1994-11-21 23:56   ` Keith Thompson
1994-11-22  3:53     ` Robert Dewar
1994-11-23 12:49     ` Michael J. Meier
1994-11-24 19:21       ` R_Tim_Coslet
1994-11-20  1:33 ` Carlos Perez
1994-11-21  5:06 ` Niklas Holsti
1994-11-21 16:19   ` Norman H. Cohen
1994-11-21 14:59 ` Mitch Gart
1994-11-21 15:40 ` Michael J. Meier
replies disabled

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