top | item 30857362

(no title)

4fips | 3 years ago

Yeah, for example passing such an opaque typedef as const is a common trap and very often source of surprise (even for the author of the API), something like:

    struct Opaque {
        int data;
    };

    typedef Opaque *OpaqueRef;

    void bar(const OpaqueRef ref) {
        ref->data = 42; // compiles fine, ref is 'Opaque *const'
    }

    void baz(const Opaque *ref) {
        ref->data = 42; // does not compile, ref is 'const Opaque *'
    }

discuss

order

No comments yet.