News for hackers. Stuff that matters.
Re:The C Programming Language: Myths and Reality (1) by dfawcus on Monday July 17, 2023 @03:09PM (#36762600)

    struct public_stuff {
        ...
    }

    struct private_stuff {
        struct public_stuff public;
        ...
    }

    struct public_stuff *make_public(/* ... */) {
        struct private *prv = malloc(sizeof *prv);
        /* ... */
        return &prv->public;
    }
Then when passed in to functions, cast the passed in struct pointer to the private one.

The public struct doesn't even have to be at the start if one make appropriate use of offsetof and ensuring valid alignment.

Nothing new under the sun...

There are no comments on this comment yet.