• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Is 'c' language an object oriented?

 
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
 
Marshal
Posts: 25812
69
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.
 
Bartender
Posts: 3225
34
IntelliJ IDE Oracle Spring Chrome Java
  • 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?
 
lowercase baba
Posts: 12893
63
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.
 
author
Posts: 23883
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux 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
 
Ranch Hand
Posts: 152
VI Editor Linux
  • 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.
 
Sheriff
Posts: 21997
107
Eclipse IDE Spring VI Editor Chrome Java Ubuntu 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
Marshal
Posts: 25812
69
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.
 
Ranch Hand
Posts: 441
Scala IntelliJ IDE 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.
 
Rancher
Posts: 4686
7
Mac OS X VI Editor Linux
  • 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.
 
Ranch Hand
Posts: 312
MS IE Java
  • 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.
 
Ranch Hand
Posts: 1246
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.
 
Marshal
Posts: 67447
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • 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.
 
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.
 
If you like strawberry rhubarb pie, try blueberry rhubarb (bluebarb) pie. And try this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic