From 07c56086aa0c4e015c9044e333ae4001debcb28d Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Tue, 30 Apr 2024 13:14:09 +0300 Subject: Update content for html --- .../2016-11-20-object-oriented-programming-with-ansi-c.html | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'gemfeed/2016-11-20-object-oriented-programming-with-ansi-c.html') diff --git a/gemfeed/2016-11-20-object-oriented-programming-with-ansi-c.html b/gemfeed/2016-11-20-object-oriented-programming-with-ansi-c.html index 05ec8102..3c8e6fad 100644 --- a/gemfeed/2016-11-20-object-oriented-programming-with-ansi-c.html +++ b/gemfeed/2016-11-20-object-oriented-programming-with-ansi-c.html @@ -8,7 +8,7 @@ -

Object oriented programming with ANSI C


+

Object oriented programming with ANSI C



Published at 2016-11-20T22:10:57+00:00; Updated at 2022-01-29

@@ -23,7 +23,7 @@
You can do a little of object-oriented programming in the C Programming Language. However, that is, in my humble opinion, limited. It's easier to use a different programming language than C for OOP. But still it's an interesting exercise to try using C for this.

-

Function pointers


+

Function pointers



Let's have a look at the following sample program. All you have to do is to add a function pointer such as "calculate" to the definition of struct "something_s". Later, during the struct initialization, assign a function address to that function pointer:

@@ -98,7 +98,7 @@ Division(3.000000 Not complicated at all, but nice to know and helps to make the code easier to read!

-

That's not OOP, though


+

That's not OOP, though



However, that's not really how it works in object-oriented languages such as Java and C++. The method call in this example is not a method call as "mult" and "div" in this example are not "message receivers". I mean that the functions can not access the state of the "mult" and "div" struct objects. In C, you would need to do something like this instead if you wanted to access the state of "mult" from within the calculate function, you would have to pass it as an argument:

@@ -109,13 +109,13 @@ http://www.gnu.org/software/src-highlite -->
mult.calculate(mult,a,b));
 

-

Real object oriented programming with C


+

Real object oriented programming with C



If you want to take it further, hit "Object-Oriented Programming with ANSI-C" into your favourite internet search engine or follow the link below. It goes as far as writing a C preprocessor in AWK, which takes some object-oriented pseudo-C and transforms it to plain C so that the C compiler can compile it to machine code. This is similar to how the C++ language had its origins.

https://www.cs.rit.edu/~ats/books/ooc.pdf

-

OOP design patterns in the Linux Kernel


+

OOP design patterns in the Linux Kernel



Big C software projects, like Linux, also follow some OOP techniques:

-- cgit v1.2.3