summaryrefslogtreecommitdiff
path: root/content/html
diff options
context:
space:
mode:
authorPaul Buetow <git@mx.buetow.org>2021-05-01 19:43:21 +0100
committerPaul Buetow <git@mx.buetow.org>2021-05-21 05:11:04 +0100
commit210e7c0349b236bfc3b78ffac8ca667efdde1d2b (patch)
tree8cba46c518c65401df546c114cfd714ba8d6bd84 /content/html
parent1890df53495b63e81e3b745b42ec6c6c1fdd1e21 (diff)
flawed
Diffstat (limited to 'content/html')
-rw-r--r--content/html/gemfeed/2016-11-20-methods-in-c.html8
1 files changed, 7 insertions, 1 deletions
diff --git a/content/html/gemfeed/2016-11-20-methods-in-c.html b/content/html/gemfeed/2016-11-20-methods-in-c.html
index 0d0bdc53..2f6ebe7d 100644
--- a/content/html/gemfeed/2016-11-20-methods-in-c.html
+++ b/content/html/gemfeed/2016-11-20-methods-in-c.html
@@ -75,8 +75,14 @@ Multiplication(3.000000, 2.000000) =&gt; 6.000000
Division(3.000000, 2.000000) =&gt; 1.500000
</pre>
<p>Not complicated at all, but nice to know and helps to make the code easier to read!</p>
+<h2>The flaw</h2>
+<p>That's actually not really how it works in object oriented languages such as Java and C++. The method call in this example is not really a method call as "mult" and "div" in this example are no "method receivers". What I mean by that is 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:</p>
+<pre>
+mult.calculate(mult,a,b));
+</pre>
+<p>How to overcome this? You need to take it further...</p>
<h2>Taking it further</h2>
-<p>If you want to take it a lot further type "Object-Oriented Programming with ANSI-C" into your favourite internet search engine, you will find some crazy stuff. Some go 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 actually similar to how the C++ language had its origins.</p>
+<p>If you want to take it further type "Object-Oriented Programming with ANSI-C" into your favourite internet search engine, you will find some crazy stuff. Some go 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 actually similar to how the C++ language had its origins.</p>
<p>E-Mail me your throughts at comments@mx.buetow.org!</p>
</body>
</html>