3 ms·
Zoom out a bit. C can trivially handle OOP concepts [1]. Any complex code base will end up with functions that look no different than object methods, with the f
by nomel 3y ago
Zoom out a bit. C can trivially handle OOP concepts [1]. Any complex code base will end up with functions that look no different than object methods, with the first argument being the equivalent of self, and class names found at the beginning of the function names MyObjectEquivelant_someMethod(MyInstanceEquivalent *pointer, ...). Here's a popular one: strlen(instance).
[1] http://staff.washington.edu/gmobus/Academics/TCES202/Moodle/OO-ProgrammingInC.html http://staff.washington.edu/gmobus/Academics/TCES202/Moodle/...
- JohnMakin 3y agoUnder the hood though they don't work remotely the same - you also aren't having things like inheritance, polymorphism, etc. - You can emulate them, I'm sure (that's a strength of C - you can do basically whatever with it) but as far as encapsulated in-memory objects with interfaces, it's just not there without a lot of goofy structs pointing to function pointers. I've only worked with C in embedded systems and the structure you're describing I've genuinely never seen, but I'll take your word for it.
- king_geedorah 3y agoI don't know that I'd agree that strlen is an example of the phenomenon you are talking about, but I also don't know that I could articulate why effectively. I do agree with your general point though. If you want an example that is obviously the same, the ALSA API[0] is about as textbook as it gets. Hell, it even names the first parameter "obj" in most of the functions for this particular subsection of functionality. [0] https://www.alsa-project.org/alsa-doc/alsa-lib/group___p_c_m___info.html https://www.alsa-project.org/alsa-doc/alsa-lib/group___p_c_m...