• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Is 'c' language an object oriented?

 
siva chaitanya
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
I cant able to understand why c language is not object oriented.
Why have functions and variables if not?
Some sites saying that c language is object oriented programming language and some are saying it is not like that.
please help me
 
Paul Clapham
Sheriff
Posts: 21554
33
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your title suggests that you believe that only object-oriented languages can have functions and variables. That is completely incorrect.
 
Mohamed Sanaulla
Saloon Keeper
Posts: 3165
34
Google App Engine Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"C" is not an object oriented language. Its procedural language.
C is not OO language- because the creators wanted it to be the way it was designed.
Can you tell us which sites tell that C is OO? May be they are talking about Objective C?
 
fred rosenberger
lowercase baba
Bartender
Posts: 12264
36
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also, be aware that "C" is a language created around 1972. Then, around 1979, it was 'enhanced' to "C with classes", and later re-named to C++.

C++ is (more or less) a super-set of C.

C did not have support for Object or any OOP principles like inheritance or polymorphism, but they were added with the C++ implementation.
 
Henry Wong
author
Marshal
Pie
Posts: 22092
88
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A look at the timelines... C, the programming language started in the late 1960's or early 1970's. Object oriented programming took off in the late 1970's or the more conservative estimate, 1980's.

So, when C was invented, Object Orient Programming won't be invented yet for anothr 10 years. I think that it is safe to assume that C is *not* an object orient language.

Henry
 
Matt Cartwright
Ranch Hand
Posts: 152
Linux VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sorry Henry, what about Lisp (70s) and Simula (-67) the predecessors of Smalltalk (-71)?

Even C++ itself is a kid of the 70s - Bell Lab's C w/ classes 1979 but 80s when it comes to the first commercial release (Glockenspiel 1985).

C has functions, not methods and there is no name space, just modules with 'private' functions declared 'static'.

What about defining a C 'struct' w/ void pointers holding functions and more pointers to other structures?
Wrap it all in macro definitions so the pre-processor extracts them to modules and voila, you have classes
Well, inheritance and encapsulation still are problems then, but I'm sure you can fix that with macros as well.

In C there is no encapsulation and no inheritance, that what makes for me the main difference of OO versus Procedural languages.
 
Rob Spoor
Sheriff
Pie
Posts: 20750
68
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Matt Cartwright wrote:Well, inheritance and encapsulation still are problems then, but I'm sure you can fix that with macros as well.

GLib and GTK have solved the inheritance problem, I believe by having the "parent" struct as a first member of the "child" struct.
 
siva chaitanya
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mohamed Sanaulla wrote:"C" is not an object oriented language. Its procedural language.
C is not OO language- because the creators wanted it to be the way it was designed.
Can you tell us which sites tell that C is OO? May be they are talking about Objective C?


yes absolutely....if c is not object oriented then what is objective c? we use objects in that....
 
siva chaitanya
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Clapham wrote:Your title suggests that you believe that only object-oriented languages can have functions and variables. That is completely incorrect.


hello Paul, In Java object's internal state is stored in variables and exposes its behavior through methods. So Java is called as object oriented programming language. C language also have functions and variables but why it is not an object oriented programming language. That's my question actually.
 
Paul Clapham
Sheriff
Posts: 21554
33
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
siva chaitanya wrote:hello Paul, In Java object's internal state is stored in variables and exposes its behavior through methods. So Java is called as object oriented programming language.


You say "Java has variables and methods, and therefore we describe it as object-oriented"? Sorry, but I repeat, that is completely incorrect. That is in no way a definition of object orientation.
 
Luigi Plinge
Ranch Hand
Posts: 441
IntelliJ IDE Scala Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Siva - it's clear you don't understand what "object oriented" means. The Wikipedia article should clarify this for you.

"C" and "Objective C" are different languages, as are BASIC and COBOL, which also have a "C" in their names. What applies to one doesn't necessarily apply to the other.
 
Pat Farrell
Rancher
Posts: 4678
7
Linux Mac OS X VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
siva chaitanya wrote:yes absolutely....if c is not object oriented then what is objective c? we use objects in that....

Objective C is an Object Oriented language that kept parts of C to ease transition and acceptance.

Java is an Object Oriented language that kept parts of C to ease transition and acceptance.

Could you, if you are seriously motivated, write ObjectOriented code in pure K&R C? Mostly. You could get close, but it would be a lot of work. You can write object oriented code in any good assembler if you are motivated.

Most modern use of Objective C is for IOS and OS-X development. If you look at the code, nearly all of the hard work is handled by the Apple frameworks. People do not write much complex "C code" in Objective C, but they could, as under it all, there is a boring old GCC compiler.
 
Madhan Sundararajan Devaki
Ranch Hand
Posts: 312
Java MS IE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
C language is not Object Oriented.

It is procedural.

Though C has variables and functions, there is no language provided way to ensure the safety of updates to the variables.

However, in Object Oriented languages such as C++ or Java you cannot update a variable in a class unless you have access to it.
 
Fei Ng
Ranch Hand
Posts: 1245
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
C Language is OO if you like to structure it that way. Thats why we have Objective C. OOB is a concept, an add-on.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65335
97
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Fei Ng wrote:C Language is OO if you like to structure it that way.

No, it is not. No matter how you structure it.

Thats why we have Objective C.

Objective-C is a different language than C.
 
Jimmy Clark
Ranch Hand
Posts: 2187
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
C and C++ are different languages are well.

When the creators of C++ were thinking about the adoption of the new language and thinking about how to get existing C programmers to use the language, they decided to incorporate everything in the C language into C++ and to make it compatible with existing C programs.

At the end of the day, C++ could then be marketed and percieved as a "super-set". But in the beginning, C++ was a very different language than C.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic