|
|
|
|
|
by kazinator
3367 days ago
|
|
You can in fact just declare struct meters in a header file, and don't publish the full declaration. The client C can still get at the data, but only in underhanded ways, like guessing at what the structure looks like and locally completing the declaration. Without that being done, the pointer cannot be dereferenced; that is a constraint violation for which ISO C requires a diagnostic. C support for making opaque data type API's is reasonably decent. You can make a type for meters that doesn't interoperate with anything but other instances of meters, other than through some serialization hole (you provide a necessary function to scan meters from a string or print to a string, and using that, someone can convert meters to just a double and add it to similiarly deserialized kilograms). |
|