c - How does Lua UTString ensure maximum alignment for strings? -
i'm reading lua's (5.3.0) source code, , in lobject.h found using strange method manipulate string follow:
/* ** header string value; string bytes follow end of structure ** (aligned according 'utstring'; see next). */ typedef struct tstring { commonheader; lu_byte extra; /* reserved words short strings; "has hash" longs */ unsigned int hash; size_t len; /* number of characters in string */ struct tstring *hnext; /* linked list hash table */ } tstring; /* ** ensures address after type aligned. */ typedef union utstring { l_umaxalign dummy; /* ensures maximum alignment strings */ tstring tsv; }utstring; /* ** actual string (array of bytes) 'tstring'. ** (access 'extra' ensures value 'tstring'.) */ #define getaddrstr(ts) (cast(char *, (ts)) + sizeof(utstring)) #define getstr(ts) \ check_exp(sizeof((ts)->extra), cast(const char*, getaddrstr(ts))) i have found answer reason of using such method in there. wondering ensures maximum alignment strings, mean? why need maximum alignment , how ensure?
Comments
Post a Comment