Thread: OOP with C

  1. #1
    ... kermit's Avatar
    Join Date
    Jan 2003
    Posts
    1,534

    OOP with C

    I have been doing a little reading on OO programming, and I have come across the idea (a couple of times) that this (OO) is definitely possible in C, albeit a little more work to implement than in C++. Anybody have any thoughts on this? Is it true, and if so, is it something worth pursuing? I am of course assuming that some of you have some experience with this.

  2. #2
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    You can do some things to encapsulate etc. You might try having a look round the web.
    http://www.accu.org/acornsig/public/articles/oop_c.html
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  3. #3
    ... kermit's Avatar
    Join Date
    Jan 2003
    Posts
    1,534
    Thanks Hammer - I should try to defend myself a little by saying that I did do a search and that is an article that I found (though I had read it earlier)

    Here is the material that sparked my interest tonight:

    http://ciips.ee.uwa.edu.au/~morris/Y...0/objects.html

  4. #4
    Pursuing knowledge confuted's Avatar
    Join Date
    Jun 2002
    Posts
    1,916
    Um, why don't you want to use C++ for your OOP? It's more 'built in' to C++, and the syntax between C and C++ is so similar that... well... I don't know. It just is. Or was this just one of those "is it possible, out of curiosity?" questions?
    Away.

  5. #5
    Comment your source code! Lynux-Penguin's Avatar
    Join Date
    Apr 2002
    Posts
    533
    looks kind of interesting to me.
    And if you look at OS code (specifically Linux) they do a lot of OOP but at the same time its not OOP *lol*
    so I guess this could definately pose usefull. Although when you deal with ADTs that have variable sized space requirements, not having a deconstructor (to automatically deconstruct) is kind of unreliable. (I.E. memory leaks)

    oh well, have fun anyway!

    -LC
    Asking the right question is sometimes more important than knowing the answer.
    Please read the FAQ
    C Reference Card (A MUST!)
    Pointers and Memory
    The Essentials
    CString lib

  6. #6
    ... kermit's Avatar
    Join Date
    Jan 2003
    Posts
    1,534
    confuted: Yeah, its kind of one of those 'Is it possible' questions. Actually it has more to do with checking if what I have been reading about it is correct. I was actually not intending to read about that subject tonight, but rather I wanted to do some reading on data structures and algorithms. The page I posted was the one I was reading, and they were talking about ADT's and OO in C. They said some things that made me wonder if they really knew what they were writing about, so I was checking. I have read somewhere that some game programmers actually will use OO type thinking in their programming, even if they are using a language that does not support OO so well. I was curious about all of this in that I have heard that OO programming is a way of thinking, or perhaps a methodology, and that it is good to learn it first. For example it would be better to learn C++ before learning C.

  7. #7
    root
    Join Date
    Sep 2003
    Posts
    232
    >Is it true
    It is indeed, but getting it to work as nicely as a language specifically designed for OO takes a lot of work and usually ends up in you writing a preprocessor like C++ started out as.

    >is it something worth pursuing?
    Nope. OO has only proven to be hands down more effective against other programming styles in GUI programming, graphics programming and simulations. Past that nobody has been able to really prove that OO buys you anything worthwhile. That's why I don't use OOP, I don't do anything with the above categories and I've never had a situation where OO is a superior method.
    The information given in this message is known to work on FreeBSD 4.8 STABLE.
    *The above statement is false if I was too lazy to test it.*
    Please take note that I am not a technical writer, nor do I care to become one.
    If someone finds a mistake, gleaming error or typo, do me a favor...bite me.
    Don't assume that I'm ever entirely serious or entirely joking.

  8. #8
    ....
    Join Date
    Aug 2001
    Location
    Groningen (NL)
    Posts
    2,380
    At work we often use OOP with C. The main reason is that we want to take advantage of OOP concepts and, we are working with embedded systems, a lot of platforms only have a C-compiler.

  9. #9
    Visionary Philosopher Sayeh's Avatar
    Join Date
    Aug 2002
    Posts
    212
    Yes, of course a certain amount of OOP is doable in C. Analysts were doing it long before an C++ or P++ language came out. About the only thing you can't do is the abstraction.
    It is not the spoon that bends, it is you who bends around the spoon.

  10. #10
    Registered User whistlenm1's Avatar
    Join Date
    Jan 2002
    Posts
    124
    Here again are we! My 2 cents, enjoy.

    http://a-sync.com/chapter2.htm

    Man's mind once streched by a new idea, never regains its original dimensions
    - Oliver Wendell Holmes

    In other words, if you teach your cat to bark (output) and eat dog food (input) that doesn't make him a dog. It would have to chase cars, chew bones, and have puppies before I'd call it Rover ;-)
    - WaltP

  11. #11
    ... kermit's Avatar
    Join Date
    Jan 2003
    Posts
    1,534
    Originally posted by whistlenm1
    Here again are we! My 2 cents, enjoy.

    http://a-sync.com/chapter2.htm

    Thanks for the link - looks like not bad reading material. There is a lot there to be sure.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. OOP flu
    By Hussain Hani in forum General Discussions
    Replies: 15
    Last Post: 06-27-2009, 02:02 AM
  2. Should OOP be any new language priority??
    By Hussain Hani in forum General Discussions
    Replies: 80
    Last Post: 06-13-2009, 10:56 AM
  3. Data Mapping and Moving Relationships
    By Mario F. in forum Tech Board
    Replies: 7
    Last Post: 12-14-2006, 10:32 AM
  4. recommendation for a good OOP book
    By Mario F. in forum C++ Programming
    Replies: 2
    Last Post: 06-15-2006, 04:28 PM
  5. OOP Theory Question
    By Zeusbwr in forum C++ Programming
    Replies: 2
    Last Post: 10-30-2005, 08:37 AM