20 ms·
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:
by 4fips 4y 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 *'
}