Skip to content

Don't pass type as named macro parameter  #157

@a-p-jo

Description

@a-p-jo

Instead of :

#define kvec_t(type) struct { size_t n, m; type *a; }

do :

#define kvec_t(...) struct { size_t n, m; __VA_ARGS__ *a; }

C macros are parsed in a very literal way, with no contextual awareness of {}, etc. So while struct { int x, y; } is a valid type, kvec_t(type) will split it into two arguments at the first , and then complain about too many parameters, while kvec_t(...) will paste the entire thing in place of __VA_ARGS__.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions