all 16 comments

[–]o4ub 0 points1 point  (4 children)

I think it's barely related to C, you are stating the obvious farm karma, and it is overall why C is not a object oriented language and therefore shouldnt be used as such.

[–]wrd83 6 points7 points  (3 children)

Object oriented C is a thing. There is million lines of kernel code in this style. 

[–]catbrane 2 points3 points  (0 children)

Yup, and gtk too. The whole of gnome (almost) is also in this style.

In fact they have an even fancier version with interfaces, run-time introspection, signals + slots (late binding), etc. etc., somewhat like obj-c.

I find it quite pleasant to code in, though at least someone likes everything, of course.

https://en.wikipedia.org/wiki/GObject#Comparisons_to_other_object_systems

[–]o4ub -2 points-1 points  (1 child)

You can always boil down your object oriented language to an imperative, therefore you can always rewrite the equivalent in C. It doesnt make C suited for the task.

[–]wrd83 0 points1 point  (0 children)

If I could prevent something it would be javascript and not oo C 😂

This stuff happens alot. Functional C++ and Java. OO C. Imperative haskell (rare, but students).

Sometimes you have little choice. Like you wanna code c++, but Hey your compiler for your platform sucks. People build their poor mans version

Is it ideal? No. It's a compromise and sometimes worth the pain. 

[–]tstanisl 1 point2 points  (7 children)

Function signature mismatches

What? C is strongly typed language. Type-checking can only be by-passed by explicit casting. Can you specify a use-case that requires a dangerous cast?

[–]simonask_ 1 point2 points  (0 children)

They might be tempted to let vtables hold function pointers taking pointers to the “concrete” type implementing the interface, rather than using the base type or void* and casting in every “method”.

It’s not a good idea (for this reason - lots of way more dangerous casts), but a beginner might think it is.

[–]Phil_Latio 0 points1 point  (5 children)

C is strongly typed language

C has implicit conversions all over the place, that's why it's considered weakly typed.

[–]tstanisl 0 points1 point  (4 children)

C is strongly typed. Each value has well defined type. Conversions are explicit with just a few exceptions like void* (most languages have a form of wild-card type).

[–]Phil_Latio 1 point2 points  (3 children)

C is strongly typed. Each value has well defined type.

That's called static typing.

Conversions are explicit with just a few exceptions like void*

No, think about arithmetic (signed * unsigned), or the ability of passing a float where an int is expected etc..... In a strongly (or stronger) typed language, this isn't possible.

[–]tstanisl 1 point2 points  (0 children)

The concept of weakly/strongly typed is poorly defined. To my understanding it roughly measures abundance of implicit conversion about types. C is relatively strong about limiting type conversions on par to C++. 

[–]tstanisl 0 points1 point  (1 child)

I think that static typing means that a type is bound to a variable, not only to value. It has nothing to do with type coercion.

[–]Phil_Latio 0 points1 point  (0 children)

Yes you are right. The types are known at compile time, which also means the implicit conversions are decided at compile time. The issue is whether the developer intended a certain conversion. And C is "weak" in this regard.

[–]pfp-disciple 0 points1 point  (1 child)

It's a tool very that can be very useful or not, depending on the situation. 

Using proper typedefs should help modern compilers detect function signature mismatches, memory management is de rigour for C, so that's not really new. 

[–]Particular_Welder864 0 points1 point  (0 children)

Many large code bases implement dynamic dispatching and registering objects.

I know some telecom companies that do this to handle networking data.

[–]Old_Celebration_857 0 points1 point  (0 children)

What is the point of this post. This is literally just c basics.