-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Invalid type in `importc: "exit"' #20694
Comments
As the Linux manual says, the use of EXIT_SUCCESS and EXIT_FAILURE is slightly more portable (to non-UNIX environments) than the use of 0 and some nonzero value like 1 or -1.
It is not the case on Windows, it supports ranges from 0x0 to 0x3e7f. I think there is no other portable way to implement quit except using For example, How about
|
This seems needlessly disruptive. If only 1-bit can really be signaled this way portably, a new While platforms vary, you need not necessarily cater to the lowest common 1-bit denominator. There can be uses for >2 values (a In that light, the old |
the "common" denominator here is 8 bits, as far as platforms go: it works for linux/bsd/osx/windows etc - windows is "special" in that it supports more bits and the standard fewer - but 8 bits is both safe and reasonably portable (and matches other api like
this difference needs to appear in the API somehow - ie misusing quit functionality should result in a compile-time failure - one way to do it is indeed to create slightly different API for different platforms, ie |
While I agree that |
saturation is not a bad option in that at least it maintains the "worked/didn't work" aspect of 0 vs non-0 - don't remember if we can overload on |
@arnetheduck yeah it's possible, e.g. proc quitMy(x: int) =
echo "quitting with ", x
proc quitMy(x: static[int]) =
echo "quitting with compile-time ", x
quitMy 5
let a = 3
quitMy a |
If you do not want to support the larger MS Windows range then you obv. don't need my internal saturation with exposed FWIW, saturation to 255 is also recommended by The Advanced Bash Scripting Guide: https://stackoverflow.com/questions/1101957/are-there-any-standard-exit-status-codes-in-linux/1535733#1535733 Another trap in this space is that Unix shells can re-code exit-via-signal as negative While that |
By the way, everything in this ticket equally applies to the weird |
* quit value gets saturated to ranges * add documentation * minimal changes * refactor * small fix * add documentation * fixes * Update lib/system.nim Co-authored-by: Juan Carlos <juancarlospaco@gmail.com> Co-authored-by: Juan Carlos <juancarlospaco@gmail.com>
var programResult* {.compilerproc, exportc: "nim_program_result".}: int
## deprecated, prefer `quit` or `exitprocs.getProgramResult`, `exitprocs.setProgramResult`. It seems that |
* quit value gets saturated to ranges * add documentation * minimal changes * refactor * small fix * add documentation * fixes * Update lib/system.nim Co-authored-by: Juan Carlos <juancarlospaco@gmail.com> Co-authored-by: Juan Carlos <juancarlospaco@gmail.com>
* quit value gets saturated to ranges * add documentation * minimal changes * refactor * small fix * add documentation * fixes * Update lib/system.nim Co-authored-by: Juan Carlos <juancarlospaco@gmail.com> Co-authored-by: Juan Carlos <juancarlospaco@gmail.com> (cherry picked from commit d5cc208)
* quit value gets saturated to ranges * add documentation * minimal changes * refactor * small fix * add documentation * fixes * Update lib/system.nim Co-authored-by: Juan Carlos <juancarlospaco@gmail.com> Co-authored-by: Juan Carlos <juancarlospaco@gmail.com> (cherry picked from commit d5cc208)
* quit value gets saturated to ranges * add documentation * minimal changes * refactor * small fix * add documentation * fixes * Update lib/system.nim Co-authored-by: Juan Carlos <juancarlospaco@gmail.com> Co-authored-by: Juan Carlos <juancarlospaco@gmail.com> (cherry picked from commit d5cc208)
* quit value gets saturated to ranges * add documentation * minimal changes * refactor * small fix * add documentation * fixes * Update lib/system.nim Co-authored-by: Juan Carlos <juancarlospaco@gmail.com> Co-authored-by: Juan Carlos <juancarlospaco@gmail.com>
What happened?
exit
takes acint
(32-bit): https://man7.org/linux/man-pages/man3/exit.3.htmlquit
in Nim takes anint
(64-bit):Nim/lib/system.nim
Line 1136 in 534c97e
in reality, only values 0-255 are well supported, but even if the full
cint
range was ok, a call toquit(0x100000000)
will result in aQuitSuccess
return code from the application after silent truncation.Nim Version
534c97e
Current Standard Output Logs
No response
Expected Standard Output Logs
No response
Possible Solution
No response
Additional Information
No response
The text was updated successfully, but these errors were encountered: