refactor: use designated initialization of array in luaX_tokens
73 views
Skip to first unread message
Melonges
unread,
Aug 6, 2024, 11:43:52 AM8/6/24
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to lua-l
I suggest using RESERVED enum in luaX_tokens array like ``` static const char *const luaX_tokens[] = {
[TK_AND] = "and",
[TK_BREAK] = "break",
[TK_DO] = "do"}; ``` this is a good approach that makes an explicit relationship between enum and array and makes it impossible to make a mistake here.
The Linux kernel source has a lot of array literals like my example above.
Francisco Olarte
unread,
Aug 6, 2024, 1:36:55 PM8/6/24
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to lu...@googlegroups.com
On Tue, 6 Aug 2024 at 17:43, Melonges <popov...@gmail.com> wrote:
> I suggest using RESERVED enum in luaX_tokens array like
> ```
> static const char *const luaX_tokens[] = { [TK_AND] = "and", [TK_BREAK] = "break", [TK_DO] = "do"};
> ```
If I am not too confused, this is C99, and lua is C89.