OO in C

This is a discussion on OO in C within the A Brief History of Cprogramming.com forums, part of the Community Boards category; Object orientation is a nice concept of programming. There are a lot of languages which can be used to implement ...

  1. #1
    ....
    Join Date
    Aug 2001
    Location
    Groningen (NL)
    Posts
    2,386

    OO in C

    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?

  2. #2
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,789
    Uhh..........C++?

  3. #3
    ....
    Join Date
    Aug 2001
    Location
    Groningen (NL)
    Posts
    2,386
    ANSI C.

  4. #4
    Unregistered
    Guest
    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

  5. #5
    Registered User zahid's Avatar
    Join Date
    Aug 2001
    Posts
    532
    wow.. I got the book..

    I have to see it. Seems interesting.

    Thank you Shiro and the Unregistered guy.
    [ Never code before desk work ]
    -------------------------------------:-->
    A man who fears Nothing is the man who Loves Nothing
    If you Love Nothing, what joy is there in your life.
    =------------------------------------------------------= - I may be wrong.

  6. #6
    Sayeh
    Guest
    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...

  7. #7
    Registered User Fool's Avatar
    Join Date
    Aug 2001
    Posts
    335
    If you want to use OOP get familiar with Java.

  8. #8
    ....
    Join Date
    Aug 2001
    Location
    Groningen (NL)
    Posts
    2,386
    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.

  9. #9
    aurė entuluva! mithrandir's Avatar
    Join Date
    Aug 2001
    Posts
    1,209
    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.

  10. #10
    Registered User zahid's Avatar
    Join Date
    Aug 2001
    Posts
    532

    Book on memory management.

    Any one know about a good (easy to understand) book on memory management in C/C++?
    [ Never code before desk work ]
    -------------------------------------:-->
    A man who fears Nothing is the man who Loves Nothing
    If you Love Nothing, what joy is there in your life.
    =------------------------------------------------------= - I may be wrong.

  11. #11
    ....
    Join Date
    Aug 2001
    Location
    Groningen (NL)
    Posts
    2,386
    C Pointers and Dynamic Memory Management
    Michael C. Daconta
    ISBN: 0-471-56152-5
    368 Pages
    September 1993

  12. #12
    Registered User zahid's Avatar
    Join Date
    Aug 2001
    Posts
    532
    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.
    [ Never code before desk work ]
    -------------------------------------:-->
    A man who fears Nothing is the man who Loves Nothing
    If you Love Nothing, what joy is there in your life.
    =------------------------------------------------------= - I may be wrong.

  13. #13
    Registered User
    Join Date
    Sep 2001
    Posts
    752
    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.
    Callou collei we'll code the way
    Of prime numbers and pings!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. global functions and OO
    By l2u in forum C++ Programming
    Replies: 2
    Last Post: 05-12-2007, 11:00 AM
  2. array bounds overflow
    By BendingUnit in forum C Programming
    Replies: 3
    Last Post: 06-18-2006, 10:45 PM
  3. The best way to read OO code?
    By geek@02 in forum C++ Programming
    Replies: 2
    Last Post: 03-07-2004, 02:02 PM
  4. OO Programming/Classes
    By rpincher in forum C++ Programming
    Replies: 7
    Last Post: 10-16-2002, 01:43 PM
  5. OO Basics
    By DISGUISED in forum C++ Programming
    Replies: 3
    Last Post: 01-04-2002, 06:25 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21