ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I was curious if any of you guys out there had ever tried to create an oop system or library for C, or at least had read through that PDF. I only got about a third of the way through. I was understanding it, but it was taking me so long that I finally decided it would probably be better to just use C++.
But then, I'm still something of a novice C programmer, so I thought perhaps some of you guys might have had better experiences.
Unless you have a very compelling reason to mimic the O-O paradigm in C I would recommend that you use C++ or another language that supports O-O if you feel that you require any of the O-O features.
I would also recommend you to take a look at the FreeBSD kernel sources, networking code is written using polymorphism in plain C and they implemented it in a very simple way. Take a look at the ifnet structure: http://fxr.watson.org/fxr/source/net...FREEBSD62#L112
Here is a tiny object-oriented C library for dynamic strings. It works like PHP's variable variables ($$var) and Python dictionaries to give you strings with names that are also strings.
dictionary_add("word","some definition");
dictionary_print("word");//prints "some definition" to the terminal
dictionary_destroy();//please destroy after use.
Distribution: Debian /Jessie/Stretch/Sid, Linux Mint DE
Posts: 5,195
Rep:
What the document describes is how to implement OOP in C. That is not that strange, after all any (compiled) OOP language is compiled into machine executable statements, and there is no reason why such a thing cannot be written in C which also compiles into machine executable statements.
However, ONLY if your goal is to learn how to develop an OO language in C, it might be worthwhile to study this document and follow the implementation.
For all other purposes it should sufficient to use an OOP language if you want to write OO programs. All the work has already been done and implemented in the compiler.
I Use OO ideas in kernel development all the time.
borrowing the ideas of the O-O paradigm is fine but trying to implement some of the concepts in pure C would miss the point, rather than making the code cleaner you would have, as Churchill once said, "a riddle, wrapped in a mystery, inside an enigma"
borrowing the ideas of the O-O paradigm is fine but trying to implement some of the concepts in pure C would miss the point, rather than making the code cleaner you would have, as Churchill once said, "a riddle, wrapped in a mystery, inside an enigma"
C++ is sometimes unadvised in kernel mode. That's why the FreeBSD developers did it in plain C. Even microsoft warns about C++ issues in kernel mode: http://www.microsoft.com/whdc/driver/kernel/KMcode.mspx
However this only happens in particular cases that only advanced programmers face, most people should just use OO languages.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.