As we can see in dirent.h
, there is a typedef:
typedef struct __dirstream DIR;
It says it's opaque to users. And we can't find it even in gcc headers, the __dirstream
structure definition can only be found in glibc source code. I am wondering why this structure has to be opaque (I don't think it's plausible to say it prevents user from direct reference, probably I am wrong)? What's the catch?
You can find the actual definition here, but as has been pointed out you're not supposed to access it directly.
It can change randomly between implementations of the standard library (or different releases of the same library) which is why it's hidden.
Your comment about "informing the user" being enough is a bit ... I don't know, it's a very optimistic outlook. Hiding the definition makes it harder to abuse it, which in turn makes it harder to write programs that violate the specification and contain pointlessly brittle code. It's a good thing; you'll find a lot of software engineering is dedicated to trying to prevent programmers from doing what they're not supposed to be doing.
This in turn is not necessarily because "all programmers are stupid", at least that's not my interpretation, it's rather since the complexity of typical software systems is very, very high, it becomes beneficial to try to reduce it whenever possible. Information hiding is one way of reducing the complexity at one particular place in the system.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With