Settings

Theme

C, Type Systems, GLib, and API Design

spurint.org

1 points by RohanAdwankar · 3 comments

Reader

1 thread
uecker

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.

  • Joker_vD

    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.
    • uecker

      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.

Keyboard Shortcuts

j
Next item
k
Previous item
o / Enter
Open selected item
?
Show this help
Esc
Close modal / clear selection