Skip to content

nob_cmd_append no longer type safe, due to relying on va args #228

@aalmkainzi

Description

@aalmkainzi

The new version makes nob_cmd_append call a variadic function, and checking for a sentinel value at the end of the list (char*)-1.

This makes nob_cmd_append compile when passing anything. I had a bug where I was accidently passing it a Nob_String_View and the generated command was nonsense (skill issue on my part, I know).

I don't know what's the best solution for this.

Maybe pass a (const char*){__VA_ARGS__} with its length?

in case of C++, maybe create a wrapper:

void nob__cmd_append(Nob_Cmd *cmd, const char **strs, size_t len);

#ifdef __cplusplus
    template <typename... Args>
    void nob__cpp_cmd_append_wrapper(Nob_Cmd *cmd, Args... strs)
    {
        const char* args[] = { strs... };
        nob__cmd_append(cmd, args, sizeof(args) / sizeof(args[0]) );
    }
    #define nob_cmd_append(cmd, ...) nob__cpp_cmd_append_wrapper(cmd, __VA_ARGS__)
#else
    #define nob_cmd_append(cmd, ...) nob__cmd_append( cmd, (const char*[]){__VA_ARGS__}, sizeof((const char*[]){__VA_ARGS__})/sizeof(char*))
#endif

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions