lua-users home
lua-l archive

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


> [...]  In C/C++, those lines always succeed, at least
> assuming no extraordinary condition (power failure, hardware failure,
> OS crash, etc.).  The reason it succeeds is that all variables used
> here, including temporaries, are allocated on the stack, and the stack
> is preallocated.  Given restrictions on things like recursion, stack
> requirements can be determined by static analysis[1].  In Lua,
> however, the stack memory is allocated incrementally from the heap
> (lua_Alloc) at unspecified times.

I guess this kind of failure is as "unspecified" in Lua as it is in
C/C++ (albeit much more frequent). As far as I know the C standard
does not specify stack requirements for functions and local variables.
So, any static analysis is implementation dependent. In Lua it is also
possible ("given restrictions on things like ...") to write programs
that use an implementation-dependent maximum amount of memory, so that
memory errors never arise.

That said, I would add that the correct answer is "Lua is not C". I must
confess that I would be very reluctant to board a plane with flight
control implemented in Lua or any other dynamic language. (Even C++
makes me nervous if I think about that :)

-- Roberto