News for hackers. Stuff that matters.
Re:Generics in C without void* or macros – enabled by psychec by bluetomcat on Monday September 09, 2019 @10:58AM (#20918790)
It seems to be aimed at quick prototyping of small programs, relieving you from declaring any structs or datatypes at all. The fields and layout of structs are inferred from the usage. With their frontend, you would be able to implement a type-generic list or a tree only with a few function definitions.

Looking at their example:

    _Generic void prepend(_Forall(node_t)** head,
                          _Forall(value_t) value)
    {
        node_t* n = malloc(sizeof(node_t));
        n->value = value;
        n->next = *head;
        *head = n;
    }
For each use of `prepend()`, their frontend defines an appropriate struct with fields `value` then `next` (in that order) whose types are inferred from the assignments in the body of the function.

There are no comments on this comment yet.