I am going through C++ FAQ by cline. It discusses about how C++ classes are better than "C-style modules". One can refer the text here.
But it doesn't discuss what a "C module" actually is. I read some texts on the net, but none of them dealt with the topic.
Can anyone explain these concepts further?
C does not have a concept of modules, as such. It has the concept of "translation unit", which is (roughly) the .c
file plus the contents of the headers it includes, directly or indirectly. The translation units get compiled independently, and then linked together into an executable program.
A translation unit gives a little bit of namespace management: you can define names of functions and variables as static
, so that they're only visible inside the translation unit. This is much less helpful than, say, C++ classes, where name conflicts are easier to avoid.
Look at languages like, say, Python, for even better solutions for that.
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