C does not have weak type safety. Nobody forces you to use void pointers, and glib is just bad in this way by not providing a safe abstraction (and why is it called gpointer?). It is entirely possible to write type safe code in C. It is also possible to write unsafe code, but this is a choice.
The language kinda forces one to use void pointers, as the path of the least resistance. I've seen your implementation of type-safe containers and it's a lot more effort (and requires rather recent version of C) than simply having a pointer-to-void as the payload.
Although GLib indeed has some rather weird design/taste.
> and why is it called gpointer?
An untyped pointer, exactly equivalent to void*.
The standard C void* type should usually be preferred in new code, but gpointer
can be used in contexts where a type name must be a single word, such as in the
GType name of G_TYPE_POINTER or when generating a family of function names for
multiple types using macros.
Hey, they do have type-generating facilities! They just don't use them to template their containers. It's a very, very old library, it predates C99.
BSD's generic macros are certainly older than C99 and I would not call this "a lot more effort". My macros are exploring a modern version of this, but people have been doing this for decades.
3 comments
[ 6.8 ms ] story [ 29.8 ms ] threadAlthough GLib indeed has some rather weird design/taste.
> and why is it called gpointer?
Hey, they do have type-generating facilities! They just don't use them to template their containers. It's a very, very old library, it predates C99.