comp.lang.ada
 help / color / mirror / Atom feed
* Handling Addressing Errors
@ 1999-03-03  0:00 Charles H. Sampson
  1999-03-04  0:00 ` robert_dewar
  1999-03-04  0:00 ` Nick Roberts
  0 siblings, 2 replies; 12+ messages in thread
From: Charles H. Sampson @ 1999-03-03  0:00 UTC (permalink / raw)


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 2027 bytes --]

     Is there a standard way to detect an addressing error, specifi-
cally, addressing a location that does not exist?

     Here is a piece of Ada 83 code that was determining dynamically if 
a slave board was present in a VME embedded system:

-----

     function CHECK_FOR_BOARD (BOARD_ADDR : in SYSTEM.ADDRESS)
      return BOOLEAN is

      BOARD_LOCATION : INTEGER;
       for BOARD_LOCATION use at BOARD_ADDR;
      BOGUS          : INTEGER;

     begin
       BOGUS := BOARD_LOCATION;
       return TRUE;

     exception
       when PROGRAM_ERROR =>
         return FALSE;    
     
     end CHECK_FOR_BOARD; 

-----

     This code worked for a particular version of a particular com-
piler, but I see a couple of problems.  The first is that, as well as I 
can tell, this is a non-standard raising of Program_error; I�ve gone 
through all references to Program_error in LRM 83 and LRM 95 and I ha-
ven�t seen this issue addressed in either.  The second is, what prevents 
an optimizing compiler from deciding that the assignment statement is 
unnecessary (BOGUS is never referenced after being set) so that it 
doesn�t need to access BOARD_LOCATION?

     As I�ve 95�ed this code I added a pragma VOLATILE (BOARD_LOCATION), 
but the definition of that pragma says that "all reads and updates of 
the object as a whole are performed direct to memory."  I think it could 
be argued that this means "all reads and updates that are necessary ..." 
and, since it's not necessary to read BOARD_LOCATION at all, the memory 
read could still be optimized away.

     I know that I can probably solve the optimization problem by put-
ting BOGUS outside of the function or even sending BOARD_LOCATION to a 
null procedure located in another package.  That should take care of all 
but the most hyper-aggressive optimizers, but it's a lot of baggage.  
I'd prefer to do something more straightforward.

				Charlie
--
******

     For an email response, my user name is "sampson" and my host
is "spawar.navy.mil".




^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~1999-04-02  0:00 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-03-03  0:00 Handling Addressing Errors Charles H. Sampson
1999-03-04  0:00 ` robert_dewar
1999-03-18  0:00   ` Charles H. Sampson
1999-03-18  0:00     ` Tucker Taft
1999-03-19  0:00       ` Mikko Levanto
1999-03-19  0:00         ` Nick Roberts
1999-03-20  0:00         ` Tucker Taft
1999-04-02  0:00       ` Charles H. Sampson
1999-03-18  0:00     ` Nick Roberts
1999-03-21  0:00       ` robert_dewar
1999-03-19  0:00     ` robert_dewar
1999-03-04  0:00 ` Nick Roberts

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