PDA

View Full Version : OO in C



Shiro
01-01-2002, 08:06 AM
Object orientation is a nice concept of programming. There are a lot of languages which can be used to implement an OO design very easily, but there are also a lot of languages which were not designed to implement OO designs, like C. Though since OO is just a concept it should be possible to implement an OO design in C, isn't it? Has anyone experience using C to implement an OO design?

Fordy
01-01-2002, 08:35 AM
Uhh..........C++?

Shiro
01-01-2002, 08:43 AM
ANSI C.

Unregistered
01-01-2002, 09:50 AM
Found a link to a book about object oriented programming in ANSI C. It seems that all concepts of OO can be implemented with ANSI C.

www.planetpdf.com/codecuts/pdfs/ooc.pdf

zahid
01-01-2002, 10:49 PM
wow.. I got the book..

I have to see it. Seems interesting.

Thank you Shiro and the Unregistered guy.

Sayeh
01-04-2002, 09:51 AM
Object Oriented programming was being done long before any OOPs language was specifically labelled as such. Where do you think the concept of OOPs came frame?

And yes, certainly in ANSI-C. The difference is it requires more work and more discipline-- one of the main reasons specific OOPs languages were developed. Programming required discipline and and truly organized mind which was beyond most people.

Back, say 20 years ago, very few people (relatively) did programming. And we were "geeks", "gurus", and "cyber geniuses" at the time. We were the only people allowed in the 'cold rooms' where the boxes hummed. We could work in low-light and have weird art on the walls. We spoke in terms nobody understood. We had libraries of books around us all the time.

The first OOPs compiler for C (called C++) was developed by a guy (Bjarne Stroustrup) who didn't like all that discipline and strict rigor associated with coding in C. He wanted to be able to abstract data types (he didn't like the grammar associated with pointers), and overload variables (use the same names for different variables), So he developed a compiler that took over the responsibility of keeping things organized. You no longer have to worry much about scope, or duplicate variable names, or any of a dozen other issues because the compiler will keep all that straight for you-- you just have to "throw the code at the wall."

And that is specifically why C++ compilers generate larger and slower code models-- they have to create code using general techniques because they dont' know what you are specifically trying to do. -- This is not a fault of the language, it is a fault of current compiler technology.

...stepping down from soapbox...

Fool
01-04-2002, 10:35 AM
If you want to use OOP get familiar with Java.

Shiro
01-04-2002, 05:42 PM
Java is far too slow and big for the systems we're working on (embedded systems). The project I'm currently working on is entirely in C. The architecture is object oriented and also the detailed designs are created using object oriented techniques, since object orientation has some very nice features. Though we're not implementing all OO features of the designs. But I thought: it must be possible to do such things like polymorphism, inheriting etc. in C only.

Some engineers say that if a design is good then it may be possible to write smaller and faster software in C++ then in C. I can imagine that object orientation in C will come up with some overhead which takes more time and space than the C++ equivalent would do. It certainly also has to do with the used compiler.

mithrandir
01-05-2002, 01:43 AM
Originally posted by Fool
If you want to use OOP get familiar with Java.

Or C# but obviously in this case, it would not be pratical. I guess that C still has some life in it yet.

zahid
01-05-2002, 04:17 AM
Any one know about a good (easy to understand) book on memory management in C/C++?

Shiro
01-05-2002, 08:50 AM
C Pointers and Dynamic Memory Management
Michael C. Daconta
ISBN: 0-471-56152-5
368 Pages
September 1993

zahid
01-05-2002, 10:28 PM
C++ Pointers and Dynamic Memory Management
Michael C. Daconta
496 pages Book&Disk edition (May 1995)
John Wiley & Sons; ISBN: 0471049980

I have seen the book at Amazon.com any more suggestion. Problem is the book is not available in Bangladesh.

QuestionC
01-05-2002, 11:02 PM
OO's really just an idea.. it just takes more typing in C (and actually, it isn't too hard to imagine how a good C++ compiler would have an easier time writing efficient OOP code). With enough pre-processing you should be able to turn a C++ program into a C program that does the same.

A book on assembly I once read actually had a chapter about OO programming, thought that was kinda interesting to run into.