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
31–40 of 196 posts
Re: I write type-safe generic data structures in C
#32Why would you jump through all these hoops instead of just writing C++ if you want "C with generics"
Re: I write type-safe generic data structures in C
#33The casting of the function type assumes that the item pointer type (e.g. Foo*) has the same representation as void*, which the C standard doesn’t guarantee (in standardese: the two types aren’t “compatible”). Calling the function with the converted type therefore constitutes undefined behavior. It also impacts aliasing analysis by compilers (see [0], incidentally), even if the pointer representation happens to be th…
Re: I write type-safe generic data structures in C
#34Re: I write type-safe generic data structures in C
#35Re: I write type-safe generic data structures in C
#36Earlier quoted context omitted.
Because for many of the use cases where C is used, switching to C++ involves jumping through even more hoops.
Do you have a couple of real world examples?
Traditionally microcontroller firmwares as well, though those are increasingly friendly to C++, you just have to be careful about allocations as C++ makes it way easier to accidentally allocate than C does.
Re: I write type-safe generic data structures in C
#37Earlier quoted context omitted.
Because for many of the use cases where C is used, switching to C++ involves jumping through even more hoops.
Do you have a couple of real world examples?
Re: I write type-safe generic data structures in C
#38The casting of the function type assumes that the item pointer type (e.g. Foo*) has the same representation as void*, which the C standard doesn’t guarantee (in standardese: the two types aren’t “compatible”). Calling the function with the converted type therefore constitutes undefined behavior. It also impacts aliasing analysis by compilers (see [0], incidentally), even if the pointer representation happens to be th…
This is addressed in the footnotes. casting is not the core of the type safety. Read the whole article.
I also don’t agree it’s “squeamish” to be wary of aliasing analysis going wrong. It’s not a clean abstraction and can hide subtle bugs down the road.