Date: Wed, 23 Jul 2025 06:56:02 -0700
On Tuesday, 22 July 2025 12:31:05 Pacific Daylight Time Arthur O'Dwyer via Std-
Proposals wrote:
> - `unsigned main()` — this is certainly a physically compatible signature
> on all platforms, but does any compiler support it today?
> - `uint8_t main()` — I'm less sure this is physically compatible (same as
> my first objection to `void main`), but it *logically* more closely matches
> how Linux treats the return code. Does any compiler support it today?
The system call on Linux takes an int:
https://codebrowser.dev/linux/linux/kernel/exit.c.html#1113
The issue is that the BSD-style wait3/4 functions store a bitfield in the int
(and compressed to the low 16 bits) so the high bits from the exit code are
lost. The newer waitid() system calls can store the full 32 bits but the
kernel caps it for compatibility.
On Windows, the system call is similar: ExitProcess() takes a full DWORD. The
C runtime function _cwait() looks similar to the POSIX/BSD functions but
isn't: it stores the full 32 bits in the pointer you pass. So on Windows, the
full 32 bits are used and suggesting use of uint8_t needs to come with some
caveats.
Proposals wrote:
> - `unsigned main()` — this is certainly a physically compatible signature
> on all platforms, but does any compiler support it today?
> - `uint8_t main()` — I'm less sure this is physically compatible (same as
> my first objection to `void main`), but it *logically* more closely matches
> how Linux treats the return code. Does any compiler support it today?
The system call on Linux takes an int:
https://codebrowser.dev/linux/linux/kernel/exit.c.html#1113
The issue is that the BSD-style wait3/4 functions store a bitfield in the int
(and compressed to the low 16 bits) so the high bits from the exit code are
lost. The newer waitid() system calls can store the full 32 bits but the
kernel caps it for compatibility.
On Windows, the system call is similar: ExitProcess() takes a full DWORD. The
C runtime function _cwait() looks similar to the POSIX/BSD functions but
isn't: it stores the full 32 bits in the pointer you pass. So on Windows, the
full 32 bits are used and suggesting use of uint8_t needs to come with some
caveats.
-- Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org Principal Engineer - Intel Platform & System Engineering
Received on 2025-07-23 13:56:19