lua-users home
lua-l archive

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


On Saturday 06 August 2005 07:34, Rici Lake wrote:
[...]
> However, as the above example demonstrates, they work pretty well in
> the same way: the compiled C file contains a string which names the
> variable, and it is looked up in a hash table (at least in ELF format).

I should point out that this is *only* true if you use dlsym() to look up 
symbols by name. When the final binary is linked together, all globals are 
resolved to individual memory locations and all the names can be discarded. 
Actually running code does not involve any run-time lookups --- the addresses 
of all globals are hard-coded.

[...]
> I did cheat a bit in the above example, of course. First, I told the
> linker not to complain about the fact that 'a' is defined by both
> main.c and a.c.

Try compiling the files the other way around...

The following link is to a IOCCC winner; it's a raytracer, written in C using 
no reserved words (this means that all globals are declared implicitly). I 
think this contains as an argument against doing this.

http://ioccc.org/2004/gavare.c

-- 
"Curses! Foiled by the chilled dairy treats of righteousness!" --- Earthworm 
Jim (evil)

Attachment: pgptHVN424K8J.pgp
Description: PGP signature