4 ms·
Undefined behavior applies internally to the language's code, not to foreign code. FFIs specify how the compiler is to invoke foreign code, how to prepare any a
by MichaelBurge 5y ago
Undefined behavior applies internally to the language's code, not to foreign code. FFIs specify how the compiler is to invoke foreign code, how to prepare any arguments, and how to handle any return values. They are not typically part of the language standard, but rather the OS standard.
Windows has different requirements for invoking foreign code vs. Linux for example.
The foreign code may have requirements on how it should be called, but it is not C's undefined behavior to invoke an OS system call incorrectly because the OS is not regulated by the C standard.
You can formally prove that a program has no undefined behavior, and it can still have lots of errors when actually run.