lua-users home
lua-l archive

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


It was thus said that the Great Robert Burke once stated:
> On Fri, Jun 11, 2021 at 1:38 PM Andrew Starks <andrew@starksfam.org> wrote:
> >
> > I'm confused by your confusion. The manual is totally clear and says
> > everything you said in fewer words.
> >
> > Undefined behavior means, in this case, adding a new key/value pair
> > while traversing a table with `next` doesn't produce an error, but is
> > incorrect because it may produce unpredictable results that are not
> > defined by the language. There is nothing overly magical about it and
> > the reason for this is self-evident — tables are not guaranteed to be
> > stable and `next` cannot know the context in which it is called.
> 
> 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

		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
		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.

  Make of that what you will.

  -spc (any typos are mine, best to check the standard for yourself, etc.)