diff options
| -rw-r--r-- | gemfeed/2016-11-20-object-oriented-programming-with-ansi-c.md | 10 | ||||
| -rw-r--r-- | index.md | 2 | ||||
| -rw-r--r-- | uptime-stats.md | 2 |
3 files changed, 7 insertions, 7 deletions
diff --git a/gemfeed/2016-11-20-object-oriented-programming-with-ansi-c.md b/gemfeed/2016-11-20-object-oriented-programming-with-ansi-c.md index 73297799..904631bd 100644 --- a/gemfeed/2016-11-20-object-oriented-programming-with-ansi-c.md +++ b/gemfeed/2016-11-20-object-oriented-programming-with-ansi-c.md @@ -17,7 +17,7 @@ You can do a little of object-oriented programming in the C Programming Language 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: -``` +```c #include <stdio.h> typedef struct { @@ -53,21 +53,21 @@ int main(void) { As you can see, you can call the function (pointed by the function pointer) with the same syntax as in C++ or Java: -``` +```c printf("%s(%f, %f) => %f\n", mult.name, a, b, mult.calculate(a,b)); printf("%s(%f, %f) => %f\n", div.name, a, b, div.calculate(a,b)); ``` However, that's just syntactic sugar for: -``` +```c printf("%s(%f, %f) => %f\n", mult.name, a, b, (*mult.calculate)(a,b)); printf("%s(%f, %f) => %f\n", div.name, a, b, (*div.calculate)(a,b)); ``` Output: -``` +```sh pbuetow ~/git/blog/source [38268]% gcc oop-c-example.c -o oop-c-example pbuetow ~/git/blog/source [38269]% ./oop-c-example Multiplication(3.000000, 2.000000) => 6.000000 @@ -80,7 +80,7 @@ Not complicated at all, but nice to know and helps to make the code easier to re 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: -``` +```c mult.calculate(mult,a,b)); ``` @@ -1,6 +1,6 @@ # foo.zone -> This site was generated at 2023-04-09T13:49:17+03:00 by `Gemtexter` +> This site was generated at 2023-04-09T13:51:48+03:00 by `Gemtexter` ``` |\---/| diff --git a/uptime-stats.md b/uptime-stats.md index 2572e831..a16cb668 100644 --- a/uptime-stats.md +++ b/uptime-stats.md @@ -1,6 +1,6 @@ # My machine uptime stats -> This site was last updated at 2023-04-09T13:49:17+03:00 +> This site was last updated at 2023-04-09T13:51:48+03:00 The following stats were collected via `uptimed` on all of my personal computers over many years and the output was generated by `guprecords`, the global uptime records stats analyser of mine. |
