lua-users home
lua-l archive

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


On 22/05/2020 17:08, Massimo Sala wrote:
Hi Andrew

MAX_SIZE isn't part of the Lua API



What do you mean? It is defined in llimits.h

1) If llimts.h isn't part of the Lua API, pardon me I don't read this
information in the official docs.

2) Whichever it is a piece of the API or just an example of declarations:
bad examples aren't useful to foster the know-how of users.


you're not supposed to care what it's defined as.


I have to take care if it is defined in such a way it breaks the
compilation on some compilers / targets.

M

That header is an implementation detail, as far as client code is concerned. That constant, as Roberto said, is not meant to be used as a general ICE by client code. Client code should interact with the Lua engine exclusively using Lua C-API, which is what is documented in the reference manual.

Any attempt to plug into other facilities defined in other header files is a hack. I.e., you are not getting any guarantee from Lua about the correctness of the code you end-up writing.

In particular, that constant is meant to be used in contexts that /don't/ trigger errors, e.g. when you write it in an expression that will be evaluated at runtime.

Anyway, this is the ever surprising legacy of C preprocessor: extreme power, but extreme hassles. Remember that the replacement text of a macro is just a list of preprocessing tokens, with almost no relation to their meaning as C-language constructs. So, technically, MAX_SIZE is not a constant, but a list of PP-tokens. With PP macros you must always think in term of expansion, not evaluation, which is not always easy nor intuitive (*sigh*).

IF one wants to make an object-like macro behave as an ICE (Integer Constant Expression) in any context, it should be extra careful. Obviously MAX_SIZE wasn't meant to be an ICE.




On Fri, 22 May 2020 at 16:46, Andrew Gierth <andrew@tao11.riddles.org.uk>
wrote:

"Massimo" == Massimo Sala <massimo.sala.71@gmail.com> writes:

 Massimo> Hi Joseph
 Massimo> That is a snippet from my code that triggers the error.

 Massimo> The problem arises beause of Lua definition of MAX_SIZE

MAX_SIZE isn't part of the Lua API, you're not supposed to care what
it's defined as.

--
Andrew.