3 ms·
How exactly does C support encapsulation? I mean, you can do OO type stuff with anonymous handles but the compiler will let a function take one handle type whe
by joe_the_user 3y ago
How exactly does C support encapsulation?
I mean, you can do OO type stuff with anonymous handles but the compiler will let a function take one handle type where another belongs and things will fail opaquely but immediately if you're luck and fail slowly if you're unlucky. Which is to say there is no "support".
- augustk 3y ago> How exactly does C support encapsulation? You simply declare a type as a pointer to a struct in the header file along with the functions that operate on variables of this type, and define the struct and the functions in the implementation file. M.h typedef struct M_TDesc *M_T; void M_Foo(M_T x); ... M.c #include "M.h" struct M_TDesc { ... }; void M_Foo(M_T x) { ... } ...
- kaba0 3y agoThat’s not encapsulation, that’s just an ugly hack. Somewhat related, it has been shown that a language with public/private visibility modifiers is more expressive than one without (that is, it can’t be locally replaced by another expression that results in the same program).
- augustk 3y ago> That’s not encapsulation, that’s just an ugly hack. Call it what you want but it works well. Declaring a variable or function as static corresponds to "private". I honestly don't understand what you mean by "locally replaced by another expression", I think you'll need to exemplify.
- hardlianotion 3y agoIs forward declaring available in C? Seems like it would have the same effect as declaring a pointer.