Earlier quoted context omitted.
Perfectly valid to do if you need to interface with a large C code base and you just want to do some simple OO here and there. Especially if you cannot have runtime exceptions and the like. This is how I managed to sneak C++ into an embedded C codebase. We even created some templates for data structures that supported static allocation at compile time.
What would be an example of "simple OO here and there" that cannot be done cleanly in plain C?
The C23 edition of Modern C
21–30 of 360 posts
Re: The C23 edition of Modern C
#22Earlier quoted context omitted.
What would be an example of "simple OO here and there" that cannot be done cleanly in plain C?
Namespaces, methods.
Re: The C23 edition of Modern C
#23Important reminder just in the Preface :-) Takeaway #1: "C and C++ are different: don’t mix them, and don’t mix them up"
Specially relevant to all those folks that insist on "Coding C with a C++ compiler", instead of safer language constructs, and standard library alternatives provided by C++ during the last decades.
https://herbsutter.com/2012/05/03/reader-qa-what-about-vc-an...
Re: The C23 edition of Modern C
#24in example 1.1 i read that as 'tits_square' until i saw the output
Re: The C23 edition of Modern C
#25Earlier quoted context omitted.
Namespaces, methods.
Namespaces is not object orientation, is it? Am I missing something? You can place functions (methods) inside of structs in C23, can't you?
I guess what you're really asking is what are the best or most common ways to do OO in C?
Re: The C23 edition of Modern C
#26Important reminder just in the Preface :-) Takeaway #1: "C and C++ are different: don’t mix them, and don’t mix them up"
A couple of months ago, in the company I work, there was a talk from HR, where they explained how to make a good CV (the company is firing lots of people). She say: "if you have experience in programming C, you can writing just that, or, if you have lots of experience in C, is customary to write ``C++ Experience'' " Sooo... yeah... I should definitely change company!
My god. That's amazing.
Re: The C23 edition of Modern C
#27Re: The C23 edition of Modern C
#28Earlier quoted context omitted.
Namespaces, methods.
Namespaces is not object orientation, is it? Am I missing something? You can place functions (methods) inside of structs in C23, can't you?
Another big one that I always forget C still doesn't support is function overloading.
Re: The C23 edition of Modern C
#29https://stackoverflow.com/questions/562303/the-definitive-c-...
Re: The C23 edition of Modern C
#30Earlier quoted context omitted.
Namespaces is not object orientation, is it? Am I missing something? You can place functions (methods) inside of structs in C23, can't you?
On a high level, "object orientation" means you think of your code as representing the state and interactions of objects. You can equally well do this in assembly. If you think of some namespace as a "singleton object" then that's what it is. I guess what you're really asking is what are the best or most common ways to do OO in C?
Where can I find something about objects being "think of your code as representing the state and interactions of objects" honesty totally new to me.
So no, certainly I'm not asking ways to do OO in C. But it seems to be more definitions of object orientation as I thought...