Date: Mon, 22 Jul 2024 08:48:10 -0700
On Monday 22 July 2024 07:45:34 GMT-7 Sebastian Wittmeier via Std-Proposals
wrote:
> If the trait supported more than one value (e.g. for different error codes),
> for example std::expected could also use it.
Indeed.
When I designed QSystemResult prior to std::expected's existence, I used the
fact that errno = 0 means "success", so any function returning void-or-error
would need only to return an int-sized object on Unix systems (for Windows, I
needed to be able to distinguish an errno from a GetLastError, so there were
two ints and therefore I could just store the "no error" as a category of
errors).
If you go down a little more in the architecture or OS, you can also know that
some values are forbidden and thus use them to store error codes. For example,
on x86, since the null pointer is not a valid pointer, the entire first page
must not be valid, so all pointers whose bitwise values are less than 4096 are
free to store error codes. For another, Linux reserves the bitwise values of
-4096 to -1 for any system call to return error codes, so those values are
never permitted in anything, like in getting the current position in a open
file.
wrote:
> If the trait supported more than one value (e.g. for different error codes),
> for example std::expected could also use it.
Indeed.
When I designed QSystemResult prior to std::expected's existence, I used the
fact that errno = 0 means "success", so any function returning void-or-error
would need only to return an int-sized object on Unix systems (for Windows, I
needed to be able to distinguish an errno from a GetLastError, so there were
two ints and therefore I could just store the "no error" as a category of
errors).
If you go down a little more in the architecture or OS, you can also know that
some values are forbidden and thus use them to store error codes. For example,
on x86, since the null pointer is not a valid pointer, the entire first page
must not be valid, so all pointers whose bitwise values are less than 4096 are
free to store error codes. For another, Linux reserves the bitwise values of
-4096 to -1 for any system call to return error codes, so those values are
never permitted in anything, like in getting the current position in a open
file.
-- Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org Principal Engineer - Intel DCAI Platform & System Engineering
Received on 2024-07-22 15:48:12