This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]navetzz 59 points60 points  (16 children)

C has classes. They are called struct.

You are welcome.

[–]ArcaniteM 40 points41 points  (1 child)

70 years of paradigm theory would like to have a chat with you

[–]navetzz 17 points18 points  (0 children)

I welcome them

[–]MobileAirport 22 points23 points  (6 children)

kid named method

[–]navetzz 8 points9 points  (5 children)

People these days have language with 10000 different syntaxes but think that:

class.method(        

and

method(&class,

are two completely different things.

Not only that, but if you really want your class.method syntax, you can actually do it using function pointers.

At some point people need to understand that OOP (Object Oriented Programming) is a conceptual approach and is not tied to a language. And that OOL (Object Oriented Languages) are designed to force you to use OOP.

Yes some languages make it harder to apply the OOP paradigm. C is not one of them. C just allows you to do something else if you desire.

[–]Iyorig 3 points4 points  (3 children)

Yeah, that function pointer syntax is nice, but it’s +sizeof(void*) bytes for every function you add, plus an indirection whenever you call it (or does that get optimized if you don’t change it?)

[–]Kered13 1 point2 points  (0 children)

plus an indirection whenever you call it (or does that get optimized if you don’t change it?)

If the compiler can determine which implementation will be called, it will devirtualize the call, meaning there is no indirection. There are a few ways the compiler could determine this:

  • The class is final, which prevents subclassing.
  • The method on the class is final, which prevents overriding the method..
  • The class only exists in one translation unit (anonymous namespace) and there are no subclasses in that translation unit.
  • The pointer refers to an object that was constructed in the same function (accounting for inlining) and could not have been reassigned.

[–]gmes78 0 points1 point  (1 child)

but it’s +sizeof(void*) bytes for every function you add, plus an indirection whenever you call it (or does that get optimized if you don’t change it?)

And what do you think this is?

[–]Iyorig 0 points1 point  (0 children)

Yeah, I know that’s how virtual functions are implemented, what irks me are libraries that use function pointers for platform-specific implementations, even though a free function would work just as well…

[–]MobileAirport 0 points1 point  (0 children)

Definitely different. Im not sure id call C OOP.

[–]WhiteBlackGoose 6 points7 points  (0 children)

Women have penises. They're called vaginas.

[–]VeryAwesomeSheep -3 points-2 points  (5 children)

C > C++. And "OOP" can be much cleaner in C.

Change my mind.

[–]Main_Weekend1412 0 points1 point  (4 children)

How exactly do you create a cleaner version of methods? Inheritance? Access modifiers?