writing to closed stdout (II): exit status

Paul Backus snarwin at gmail.com
Sun Dec 15 19:02:33 UTC 2024


On Sunday, 15 December 2024 at 18:46:26 UTC, kdevel wrote:
> 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:

I did some more digging and it turns out that this is a feature 
of the GNU C runtime (i.e., the code that calls `main`):

>  While nominally the return value is of type `int`, in fact the 
> exit status gets truncated to eight bits; if `main` returns the 
> value 256, the exit status is 0.

https://www.gnu.org/software/c-intro-and-ref/manual/html_node/Values-from-main.html


More information about the Digitalmars-d mailing list