You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Maybe there's an alternative way to do this that makes more sense, but when I'm using kvec the struct is anonymous. Maybe this works for C++, but it drives most C compilers crazy when you need to pass kvecs by value or reference to a subroutine since only C11 even knows about anonymous structs.
I solved this by: #define kvec(type) struct kv_##type##_s { size_t n, m; type *a; } #define kvec_t(type) struct kv_##type##_s
Then put kvec(int); in your headers and kvec_t(int) in your variable definitions and parameter references.
The text was updated successfully, but these errors were encountered:
@jvburnes , isn't it a C99 feature ?
My bad. It worked on -std=c99 so I assumed this. Very odd, given this comment :
The irony is that the semantics afforded by anonymous structs and unions were available in Dennis Ritchie's 1974 C compiler, and I think gcc had supported anonymous structs and unions in the days prior to the C89 Standard. Some people seem to think it's a new feature, but it merely represents a regained ability that should never have been lost.
Maybe there's an alternative way to do this that makes more sense, but when I'm using kvec the struct is anonymous. Maybe this works for C++, but it drives most C compilers crazy when you need to pass kvecs by value or reference to a subroutine since only C11 even knows about anonymous structs.
I solved this by:
#define kvec(type) struct kv_##type##_s { size_t n, m; type *a; }
#define kvec_t(type) struct kv_##type##_s
Then put
kvec(int);
in your headers andkvec_t(int)
in your variable definitions and parameter references.The text was updated successfully, but these errors were encountered: