From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-0.5 required=5.0 tests=BAYES_00,INVALID_MSGID, PP_MIME_FAKE_ASCII_TEXT autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII X-Google-Thread: 103376,e8d2c0ed82daf4da,start X-Google-Attributes: gid103376,public From: claveman@cod.nosc.mil (Charles H. Sampson) Subject: Handling Addressing Errors Date: 1999/03/03 Message-ID: <1999Mar3.212443.1898@nosc.mil>#1/1 X-Deja-AN: 451072440 Sender: news@nosc.mil Organization: Computer Sciences Corporation Newsgroups: comp.lang.ada Date: 1999-03-03T00:00:00+00:00 List-Id: 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".