jQuery in Action, 2nd edition*
The moose likes Other Languages and the fly likes Is 'c' language an object oriented? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Languages » Other Languages
Bookmark "Is Watch "Is New topic
Author

Is 'c' language an object oriented?

siva chaitanya
Ranch Hand

Joined: Jul 05, 2011
Posts: 59
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
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

Your title suggests that you believe that only object-oriented languages can have functions and variables. That is completely incorrect.
Mohamed Sanaulla
Saloon Keeper

Joined: Sep 08, 2007
Posts: 3068
    
  33

"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?


Mohamed Sanaulla | My Blog
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11257
    
  16

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.


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18765
    
  40

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


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Matt Cartwright
Ranch Hand

Joined: Aug 25, 2008
Posts: 149

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

Joined: Oct 27, 2005
Posts: 19685
    
  20

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.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
siva chaitanya
Ranch Hand

Joined: Jul 05, 2011
Posts: 59
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

Joined: Jul 05, 2011
Posts: 59
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
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

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

Joined: Jan 06, 2011
Posts: 441

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

Joined: Aug 11, 2007
Posts: 4650
    
    5

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

Joined: Mar 18, 2011
Posts: 312

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.


S.D. MADHAN
Not many get the right opportunity !
Fei Ng
Ranch Hand

Joined: Aug 26, 2000
Posts: 1242
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

Joined: Jan 10, 2002
Posts: 61106
    
  66

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.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Jimmy Clark
Ranch Hand

Joined: Apr 16, 2008
Posts: 2187
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Is 'c' language an object oriented?