Our great sponsors
-
InfluxDB
Power Real-Time Data Analytics at Scale. Get real-time insights from all types of time series data with InfluxDB. Ingest, query, and analyze billions of data points in real-time with unbounded cardinality.
-
STC
A modern, user friendly, generic, type-safe and fast C99 container library: String, Vector, Sorted and Unordered Map and Set, Deque, Forward List, Smart Pointers, Bitset and Random numbers. (by stclib)
One way around this problem is to declare the container as a pointer to the element type and then store the container’s metadata, alongside its elements, in the heap block to which the pointer points. This approach is already used for dynamic arrays in several container libraries, most notably stb_ds and sds. They place the metadata before the elements and provide the user with a pointer to the elements themselves (this has the nice effect that users can use the [] operator to access elements).
One way around this problem is to declare the container as a pointer to the element type and then store the container’s metadata, alongside its elements, in the heap block to which the pointer points. This approach is already used for dynamic arrays in several container libraries, most notably stb_ds and sds. They place the metadata before the elements and provide the user with a pointer to the elements themselves (this has the nice effect that users can use the [] operator to access elements).
… and then used the _Generic mechanism to provide a fully generic API for the generated types and functions. That approach has some advantages over the approach that CC now takes – it’s simpler, it relies on fewer novel tricks, the code is far easier to understand, it works with the language rather than against or around it, it doesn’t lead to a macro hellscape, etc. But it requires the user to define types, and I felt that eliminating this requirement was important to CC’s identity as a “convenient” library. (Also, I was motivated by the recent standardization of typeof to try something that exploits it.) But maybe someone else can take this technique and use it to make something like the original iteration of CC, or make a generic API for an existing, more broadly scoped container library ( u/operamint ).