[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: [ANN] Lua 5.4.0 (rc3) now available
- From: Roberto Ierusalimschy <roberto@...>
- Date: Tue, 12 May 2020 10:34:14 -0300
> typedef struct TString {
> CommonHeader;
> lu_byte extra;
> lu_byte shrlen;
> unsigned int hash;
> union {
> size_t lnglen;
> struct TString *hnext;
> } u;
> char bytes[1];
> } TString;
>
> #define getstr(ts) check_exp(sizeof((ts)->extra), ts->bytes)
>
> #define sizelstring(l) (sizeof(TString) + (l) * sizeof(char))
This code wastes up to seven bytes (due to alignment), compared with
the original version. A better option would be to use 'offsetof' to
compute the size of the rest of the structure:
#define sizelstring(l) (offsetof(TString, bytes) + ((l) + 1) * sizeof(char))
I hope the new gcc does not complain about that code.
-- Roberto
_______________________________________________
lua-l mailing list -- lua-l@lists.lua.org
To unsubscribe send an email to lua-l-leave@lists.lua.org