lua-users home
lua-l archive

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


> Not sure why the end result is cast as an int, nor why the buffer is
> defined as a one element array rather than a pointer... I suppose it
> is meant to keep the compiler happy, I'm not a C expert at all.

The buffer is not a pointer, it is the buffer itself. As you explained,
the LPeg compiler allocates the correct space in the opcode array. If
buff was declared with its correct size, all instructions would need
those additional 32 bytes. So, it is declared with size 1 (C89 does
not allow zero-sized arrays) just as a place holder. This is a common
technique in C (see [1], for instance). 

[1] http://gcc.gnu.org/onlinedocs/gcc/Zero-Length.html

-- Roberto