writing to closed stdout (II): exit status

kdevel kdevel at vogtner.de
Sun Dec 15 18:46:26 UTC 2024


On Sunday, 15 December 2024 at 17:16:11 UTC, Paul Backus wrote:
> On Sunday, 15 December 2024 at 14:32:13 UTC, kdevel wrote:
>> Surprisingly when the return value is anything but 0 the exit 
>> code of the program becomes `rv & 255`.
>
> The POSIX standard specifies that the status code you get from 
> `wait` and `waitpid` is truncated to 8 bits.

Sure. My wording is somewhat misleading. What I find surprising 
is that if 256 is returned the exit status of the program becomes 
0 whereas it becomes 1 in the case of a returned 0:

```
$ cat return0.d
int main ()
{
    import std.stdio;
    writeln ("OK.");
    return 0;
}
$ dmd -run return0 1>&-; echo $?
Failed to flush stdout: Bad file descriptor
1
$ cat return256.d
int main ()
{
    import std.stdio;
    writeln ("OK.");
    return 256;
}
$ dmd -run return256 1>&-; echo $?
Failed to flush stdout: Bad file descriptor
0
```


More information about the Digitalmars-d mailing list