Why would you jump through all these hoops instead of just writing C++ if you want "C with generics"
I write type-safe generic data structures in C
111–120 of 196 posts
Re: I write type-safe generic data structures in C
#112Earlier quoted context omitted.
I know it used to be, but is it really still common for embedded systems to use weird architectures that G++/Clang don't support?
Unless it is a popular system or common architecture, yes.
> yes, unless you're using a common one.
Re: I write type-safe generic data structures in C
#113With similar articles in The C/C++ Users Journal and Dr Dobbs, throught their existence.
While the effort is commendable, maybe pick a safer language that actually has all the features for type safe generic code.
Re: I write type-safe generic data structures in C
#114Earlier quoted context omitted.
Why would you write C++ if you can get the same result by jumping through a few hoops with C?
Templates in C++ require language support - you can't simply implement them with "a few hoops" in C.
Re: I write type-safe generic data structures in C
#115Earlier quoted context omitted.
In what situation fn() doesn't mean fn(void) under C23?
None, but that is not my point. Before C23, fn() already meant the same thing as fn(void) in function definitions , which the situation under discussion here. C23 changed what fn() means outside a function definition.
Re: I write type-safe generic data structures in C
#116Re: I write type-safe generic data structures in C
#117Earlier quoted context omitted.
Templates in C++ require language support - you can't simply implement them with "a few hoops" in C.
Templates are a solution for a problem that c++ themselves created
Re: I write type-safe generic data structures in C
#118Earlier quoted context omitted.
> it should be `int main() { List(Foo) foo_list = {NULL};` In C `int main()` means the function takes an unknown number of arguments. You need `int main(void)` to mean it doesn't take any arguments. This is a fact frequently forgotten by those who write C++.
This is incorrect. In a function definition, an empty list means it takes no parameters. 6.7.5.3 Function declarators > 14. An empty list in a function declarator that is part of a definition of that function specifies that the function has no parameters.
https://stackoverflow.com/questions/156767/whats-the-differe...
Re: I write type-safe generic data structures in C
#119Earlier quoted context omitted.
i am firmly of the opinion that compiling to c is a better route than doing clever c tricks to sort of get what you want. the compiler can be pretty minimal and as you note it pays for itself.
There’s some prior work called CFront. It implements a superset of C that’s just an “increment”. I think it’s worth looking into, it might take off one day!
Re: I write type-safe generic data structures in C
#120Or write in CFront and have it translated to C
And where are you going to get a cfront compiler these days?