4 ms·
What does not checking a syscall error have to do with the language?
by resist_futility 6y ago
What does not checking a syscall error have to do with the language?
- a_t48 6y agoNot sure if Swift has the mechanisms to do it, but for example, you could wrap your syscalls in something that requires an error to be checked. In C++ it can only be a runtime check (outside of extensions?). I _think_ Rust might allow a compile time check but I don't remember which mechanism you'd do it from. Don't know about Swift. Edit: of course you're always allowed to check and discard the error. No language can stop people from purposefully shoot themselves in the foot, but at least safeties can be installed.
- fools 6y agoRust has compile-time warnings for when you don't use the result of a function whose return type is marked as #[must_use]. You can easily silence such a warning by writing `let _ = f(...)`, though, but I don't think that's a bad thing.
- detaro 6y agoC++ has the nodiscard attribute for this now.
- saagarjha 6y agoFunctions in Swift must be annotated to allow discarding their results without a warning.
- cozzyd 6y agoAt least on on my system, ftruncate is annotated with __wur, so a simple -D_FORTIFY_SOURCE would suffice to produce a warning in this case.