lua-users home
lua-l archive

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

On Mon, Nov 19, 2018 at 10:10 AM Dirk Laurie <> wrote:
1. All external names used by Lua are declared in header files.
2. If such a name has been resolved by an object file or library
linked earlier, the linker will be satisfied and will not replace it.
3. Any .o files needed by the linker will be built automatically from
.c files by the Makefile rules.

No. Quoting clause 6.9/5 of the C11 standard:

If an identifier declared with external linkage is used in an _expression_ (other than as part of the operand of a sizeof or _Alignof operator whose result is an integer constant), somewhere in the entire program there shall be exactly one external definition for the identifier; otherwise, there shall be no more than one.


The standard has no concept of "linked earlier" and consequently no primacy of "names linked earlier", and the entire program, including all the libraries, shall have a function with a given name defined at most once. Per clause 4/2, "If a ‘‘shall’’ or ‘‘shall not’’ requirement [...] is violated, the behavior is undefined".

Note that what you do may fail in weird ways even with toolchains that do have the notion of "linked earlier" - precisely because something has been linked earlier. Your application may be using the "modified" functions, while Lua itself and the other libraries use the "original" functions. This would be a special case of generally undefined behaviour.

Do not do this, except for fun.