Is the C programming language object-oriented?

后端 未结 16 1165
我寻月下人不归
我寻月下人不归 2021-01-30 16:22

I was talking with a co-worker about C and C++ and he claimed that C is object-oriented, but I claimed that it was not. I know that you can do object-oriented-like things in C,

相关标签:
16条回答
  • 2021-01-30 17:15

    No, it is not, your friend is wrong.

    0 讨论(0)
  • 2021-01-30 17:16

    Unless your friend was talking about Objective C (an OO superset of C) then no, C isn't an OO language. You can implement OO concepts using C (that's what the old cfront C++ compiler did, it translated C++ into C) but that doesn't make C an OO language as it doesn't specifically offer support for standard OO techniques like polymorphism or encapsulation.

    Yes, you can write software OO style in C, especially with liberal (ab-)use of macros but as someone who has seen the results of some of those attempts, I'd strongly suggest to use a better suited language.

    0 讨论(0)
  • 2021-01-30 17:17

    Answer can be yes or no, depending on:

    • if you ask "is C an object oriented language?", the answer is "no" because it do not have object oriented constructors, keywords, semantic etc...

    • if you intend "can I realize OOP in C?", the answer is yes, because OOP is not only a requirement of a language, but also a way of "thinking", an approach to programming, before to touch some language or another. However the implementation of OOP in C (or any other language not natively designed to be OOP) will be surely "forced" and much hard to manage then any other OOP language, so also some limitation shall be expected.

    0 讨论(0)
  • 2021-01-30 17:20

    C isn't object oriented. That was the entire purpose behind the ++

    As far as a definition of what it takes to be object oriented: check wikipedia.

    Personally, if it supports inheritance, encapsulation, and polymorphism then your good to go. Another key here is having nice keywords like class and object tend to help...

    Examples of real object oriented languages (not conclusive) are: Smalltalk, Java, c#, Python, Ruby, C++..

    Also, it's possible to have extensions to provide OO features like PHP, Perl, VB (not .Net), ...

    0 讨论(0)
提交回复
热议问题