lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

On Tue, Apr 17, 2018 at 5:34 PM, Roberto Ierusalimschy <> wrote:

> As far as my English goes, "undefined" means "not defined". So, if it not defined, it is undefined. We some times do it, but to say that behavior is undefined reminds me of "This page intentionally left blank".

In C and C++ circles, "undefined behavior", frequently shortened to just UB, is a term defined in the language standard. In C:

1 undefined behavior
behavior, upon use of a nonportable or erroneous program construct or of erroneous data,
for which this International Standard imposes no requirements
2 NOTE Possible undefined behavior ranges from ignoring the situation completely with unpredictable
results, to behaving during translation or program execution in a documented manner characteristic of the
environment (with or without the issuance of a diagnostic message), to terminating a translation or
execution (with the issuance of a diagnostic message).
3 EXAMPLE An example of undefined behavior is the behavior on integer overflow

When we read an API spec that says "this is undefined behavior", we mentally substitute that with "it can crash or format your hard drive; do not do this". When we read a spec that does not say that, we do not always understand that some combinations of input will result in THAT kind of UB; for example, I expected a Lua error to be raised by lua_next() when given a non-table input (why? perhaps because it had the 'e" error category?). So even though it feels like stating the obvious, it helps.