lua-users home
lua-l archive

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

> > Well, this whole discussion exists because in some other contexts
> > "undefined behavior" means that when you do this the program is
> > permitted to email your boss some insults instead of returning a key
> > from the table or nil.
>   I don't think any standard actually states that (although if any do,
> please, by all means, provide a reference).  The poster boy for undefined
> behavior, C, states in its standard (both C99 and C11), section 3.4.3:
> 	1	undefined behavior
> [...]
> 	2	NOTE Possible undefined behavior ranges from ignoring the
> 		situation completely with unpredictable results, to behaving
> 		during translation or program execution in a documented
> 		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).

The reference is the manual itself:  "Possible undefined behavior
ranges from ignoring the situation completely with unpredictable
results". Seding an email insulting your boss is an example of
an unpredictable result.

Each language has its own concept of "undefined behavior" or try
not to have any. The concept used in C/C++ became the most known
exactly because of the its absurd (and unespected, for the amateurs :-)
consequences in some very real cases [1]. The manual uses "undefined
behavior" in their usual English meaning, not in the specific
meaning of C. Anyway, to avoid confusion, we will avoid the term.

[1] Consider this example, copied from Stack overflow:

int main(void)
  int ch = getchar();
  if (ch < 74)
    printf("Hey there!");

When ch is 74 or greater, the product ch*ch*ch*ch*ch will overflow,
which is undefined behavior. So, the compiler is free to optimize
that program to this one:

int main(void)
  printf("Hey there!");

Nowadays, several compilers do that sort of things.

-- Roberto