Re: return code wierdness
Posted in 1994
Jack Parker (jparker@hpbs3645.boi.hp.com) wrote: : Could one of you informix blokes explain this? : 1) : From 4gl: : RUN command RETURNING retcode : # Command exits with a return code of 4 : DISPLAY retcode # displayed value is 256*4 - or 1024 : 2) : From 4gl: : exit program 3 : OS says return code is 3 : 3) : From 4gl: : exit program -3 :OS says return code is 253 (256 + return code) : mazeltof : j. : _____________________________________________________________________________ : Jack Parker | Are you using a Intel 80x86 based platform? The Intel 80x86 chips stack their bytes in a different order than other systems. Most systems will look at 16-bit integer as a high order byte and a low order byte, reading left to right. Intel views the byte as a low order byte and then a high order byte, again reading left to right. To port binary data from an Intel box to pretty much anything else means that the numeric bytes must be "manually" flipped so that the other machine will read them in proper order. What I imagine is happening with the RUN statement is that the statement does not know that it is on an Intel platform and is not doing the flip to get the proper return value. The value 4 as a 16 bit integer is 0000 0000 0000 0010. The value 1024 as a 16 bit integer is 0000 0010 0000 0000. Please note that the two 8-bit segments are swapped in the two numbers. For some reason the bytes are put in proper order when the 4gl program returns to the operating system, and the operating system sees the bytes in the order that it expects. So you see the proper return code. When you use a negative number you are also running into the two's complement phenomenon. A two's complement is a way of expressing negative integers so that there is no negative 0. The negative number is generated by doing a logical XOR of the integer with a word length of 1's (a 16-bit word requires 16 1's), and then 1 is added to the result. To make an 8-bit representation of -3, first take the binary 0000 0011, then XOR it with the mask 1111 1111 to get 1111 1100. Add 1 to get 1111 1101. If you are using an Intel chip your -3 has an internal representation of 1111 1101 1111 1111 (all 16 bits are used). On our platform, SCO Unix, the operating system only looks at the first 8 bits of an exit code. In this instance, it will see the value of 253. Why does Informix not fix the return from RUN? Maybe noone could ever get through tech support. -- Usenet News | Group One, Ltd. | usenet@group1.com | 220 Bush St. #240 | News Administration | San Francisco, Ca. | | 94104 |