Rainier:
On Mon, Nov 9, 2020 at 5:53 PM Ranier Vilela <ranier.vf@gmail.com> wrote:
> Em seg., 9 de nov. de 2020 às 13:48, Luiz Henrique de Figueiredo <lhf@tecgraf.puc-rio.br> escreveu:
>> > - for (i=0; i < LUA_NUMTAGS; i++) g->mt[i] = NULL;
>> > + memset(g->mt, 0, sizeof(struct Table *) * (size_t) LUA_NUMTAGS);
>> No. The C standard says that NULL does not need to have all bits zero.
> Change 0 by NULL, after the memset, the memory has the same content.
> - for (i=0; i < LUA_NUMTAGS; i++) g->mt[i] = NULL;
> + memset(g->mt, NULL, sizeof(struct Table *) * (size_t) LUA_NUMTAGS);
> Internally, memset has its own loop, but this is very highly optimized for the platform used.
The second parameter to memset is an int. NULL must cast to 0 as an
int. But using it there is grossly missleanding.
OTOH, what Luis tries to tell you is that NULL can be represented as
something different than a 0 filled byte array. As long as it cast to
0 everything is fine.
Granted, all the platforms I've used use an all-zeroes representation,
but lua does not have the luxury of assuming that.
I never see any platform that NULL is not all-zeroes representation.
Ranier Vilela