HP OpenVMS Systemsask the wizard |
The Question is: I have problems using RTL functions in a C++ program using IEEE floats. The following program will not run: #include <stdio.h> #include <lib$routines.h> #pragma nomember_alignment main() float f1 = 1.0; lib$wait(&f1); I compile it with the following commands: $ cxx/float=IEEE_FLOAT example.cxx $ cxxlink example.cxx When I run the program it crashes. I hope you can help me out. The Answer is : Arguably far easier and far simpler than this current approach will be a call to the C library sleep routine. As for this problem, the "seconds" argument for the OpenVMS Run-time library (RTL) routine lib$wait is interpreted as F_floating floating point data type -- please see the extract from the HELP text attached below for argument information. The run-time error: %SYSTEM-F-HPARITH, high performance arithmetic trap, Imask=00000000, Fmask=00000400, summary=02, PC=FFFFFFFF80489C24, PS=0000001B -SYSTEM-F-FLTINV, floating invalid operation, PC=FFFFFFFF80489C24, PS=0000001B indicates that the IEEE floating point format "1.0" is an invalid bit pattern for the F_floating floating point data format. If you wish to use the lib$wait call in a module that is compiled with the IEEE floating point format (/FLOAT=IEEE_FLOAT), you will need to perform an explicit floating point conversion. For example, you could convert the floating point value or you could ask the lib$wait call to appropriately interprete the floating point value: #include <cvt$routines.h> #include <cvtdef> #include <lib$routines.h> #include <libwaitdef.h> #include <ssdef.h> #include <stdio.h> #include <stsdef.h> main() { float ieee_s = 1.0; int vax_f; int RetStat; int float_type = LIB$K_IEEE_S; RetStat = cvt$ftof(&ieee_s,CVT$K_IEEE_S,&vax_f,CVT$K_VAX_F,0); if (!$VMS_STATUS_SUCCESS( RetStat )) return RetStat; RetStat = lib$wait(&vax_f); if (!$VMS_STATUS_SUCCESS( RetStat )) return RetStat; RetStat = lib$wait(&ieee_s, 0, &float_type); if (!$VMS_STATUS_SUCCESS( RetStat )) return RetStat; return SS$_NORMAL; } Use of correctly-aligned data is strongly recommended for reasons of performance -- the #pragma nomember_alignment call should only be used when you must explicitly support unaligned data references. Since there is no reason in this example not to use aligned data, the pragma has been removed. (Please see the OpenVMS FAQ for further details.) The inclusion of explicit return status checks are strongly recommended. Failure to perform such checks is a common source of run-time problems -- often, obscure run-time problems. Please see topic (1661) for other common run-time coding problems. Available information on the RTL call and on the return HPARITH status code: $ HELP RTL LIB$ LIB$WAIT RTL_ROUTINES LIB$ LIB$WAIT Arguments seconds OpenVMS usage:floating_point type: F_floating access: read only mechanism: by reference The number of seconds to wait. The seconds argument contains the address of an F-floating number that is this number. The value is rounded to the nearest hundredth-second before use. Seconds must be between 0.0 and 100,000.0. $ HELP/MESSAGE HPARITH HPARITH, high performance arithmetic trap, Imask='xxxxxxxx', Fmask='xxxxxxxx', summary='xx', PC='xxxxxxxx', PS='xxxxxxxx' Facility: SYSTEM, System Services Explanation: The image performed an arithmetic or conversion operation that resulted in an arithmetic trap. When an arithmetic exception condition is detected, several instructions can be in various stages of execution. These instructions are allowed to finish before the arithmetic trap can be initiated. Some of these instructions can themselves cause further arithmetic traps. Thus it is possible for several arithmetic traps to be reported simultaneously. The Imask parameter records all integer registers that were targets of the instructions that set the bits in the exception summary. Bit 0 corresponds to R0, bit 1 corresponds to R1, and so on. The Fmask parameter records all floating-point registers that were targets of the instructions that set the bits in the exception summary. Bit 0 corresponds to F0, bit 1 corresponds to F1, and so on. The exception summary parameter records the various types of arithmetic traps that can occur together: ______________________________________________________________ Bit Set_____Meaning_______________________________________________ Bit 0 Software Completion All the other arithmetic exception bits were set by floating-operate instructions with the /S software completion trap modifier set. Bit 1 Invalid Operation An attempt was made to perform a floating arithmetic, conversion, or comparison operation, and one or more of the operand values was illegal. Bit 2 Division by Zero An attempt was made to perform a floating divide operation with a divisor of 0. Bit 3 Overflow A floating arithmetic or conversion operation overflowed the destination exponent. Bit 4 Underflow A floating arithmetic or conversion operation underflowed the destination exponent. Bit 5 Inexact Result A floating arithmetic or conversion operation gave a result that differed from the mathematically exact result. Bit 6 Integer Overflow An integer arithmetic operation or a conversion operation from floating to integer overflowed the __________destination_precision.______________________________ The PC parameter is the virtual address of the next instruction. This is defined as the virtual address of the first instruction not executed after the trap condition was recognized. User Action: Check the program listing to verify that the operands or variables are specified correctly.
|