Mail Archives: djgpp/1995/04/26/16:40:26
Tony> I just had some troubles with exitcodes:
Tony> I left a program, called with a spawnlp() from a second program, with
exit(-2). The result was that spawnlp() returned 254.
Tony> Code:
.....
>From the docs:
Tony> void volatile exit(int exit_code);
Tony> and
Tony> int spawnlp(...)
Tony> That means both, the parameter of exit() and the return value of
Tony> spawnlp() are int.
Tony> I remember having read long time ago that DOS can only handle errorcodes
Tony> 0...255.
Tony> (is that correct ?) Therefore it is not a DJGPP but a DOS problem.
Tony> I finally declared
Tony> signed char en;
Tony> and got corrrect behavior for negative exitcodes.
Tony> This is just a workaround. What is the correct procedure to deal with
Tony> exitcodes (in a portable way) ?
In spite of the "int exit_code" declaration, to be portable, the exit codes
should be treated as unsigned char . This is what unix(tm) uses. (I know,
I've just been through the same exercise :-) Some unix shells seem to
pretend that the exit codes are int's. But "the low order 8 bits of
exit_code are made available to the parent process". The implication could
be that "signed char" is reasonable as long as one remembered that the
range is -128 through 127. The implication of the DOS 0 through 255 is
that it really should be considered unsigned.
Jim
- Raw text -