lua-users home
lua-l archive

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


Roberto Ierusalimschy <roberto@inf.puc-rio.br> 于2020年5月13日周三 上午12:28写道:
>
> 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))

'offsetof' would be better. And gcc allows 'char bytes[0];' or 'char bytes[];' .

It's C99 standard, but MSVC doesn't support it :(

https://stackoverflow.com/questions/20221012/unsized-array-declaration-in-a-struct


-- 
http://blog.codingnow.com
_______________________________________________
lua-l mailing list -- lua-l@lists.lua.org
To unsubscribe send an email to lua-l-leave@lists.lua.org