Thread: Polymorphism in C

  1. #1
    Registered User
    Join Date
    Feb 2011
    Posts
    52

    Polymorphism in C

    Me and my friends have had an argument over this topic.
    Is it anyway possible to implement polymorphism in C?????

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Yes. If you want details, search the Web.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Feb 2011
    Posts
    52
    Polymorphism in C NOT in C++...!!!

    I tried google but what all i found was C++ codes. Would you please take the trouble of explaining me things or post some good links?

  4. #4
    Registered User
    Join Date
    Sep 2007
    Posts
    131
    Polymorphism in C - CodeProject®
    Inheritance and Polymorphism in C - CodeProject®

    Both articles start by showing C++ polymorphism, but then move onto a C implementation.

  5. #5
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by Avenger625
    Polymorphism in C NOT in C++...!!!
    Note that:
    • I can read what you write.
    • I know which forum I am in when I post.
    • I do not confuse C and C++.
    • I have done exercises that simulate OOP in programming languages that either do not support certain OO techniques natively, or which was merely an exercise in simulating OOP.
    • I have partially read a fairly comprehensive article on simulating OOP in C.


    Quote Originally Posted by Avenger625
    I tried google but what all i found was C++ codes
    Before telling you to search the Web for details, I entered polymorphism in C into Google just in case C++ articles would have dominated the search. The first three results I got were concerned with C. The fourth was concerned with C#, the fifth was the Wikipedia article on polymorphism in computer science, and the next two were again about polymorphism in C. The first C++ specific entry was the tenth. So, if all that you found was on C++, I wonder at what search terms you used, or maybe your search engine just sucks
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  6. #6
    Registered User
    Join Date
    Feb 2011
    Posts
    52
    When it is possible to simulate OOP features into C then y dont we call it an OOP language?????

  7. #7
    Technical Lead QuantumPete's Avatar
    Join Date
    Aug 2007
    Location
    London, UK
    Posts
    894
    Quote Originally Posted by Avenger625 View Post
    simulate OOP features
    The answer is in the question. C is not an OOP language, but can simulate the concepts. Same way you can use imperative statements in some data-driven languages, but that doesn't make them imperative programming languages.
    "No-one else has reported this problem, you're either crazy or a liar" - Dogbert Technical Support
    "Have you tried turning it off and on again?" - The IT Crowd

  8. #8
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    Quote Originally Posted by Avenger625 View Post
    When it is possible to simulate OOP features into C then y dont we call it an OOP language?????
    Simulation - Definition and More from the Free Merriam-Webster Dictionary
    Definition of SIMULATION
    3a : the imitative representation of the functioning of one system or process by means of the functioning of another <a computer simulation of an industrial process>
    Note: I have used C to simulate Assembly; but, I would never call C Assembly.
    Note: I have also use Macros to make C like Pascal; but that does not make C a Pascal language.

    Tim S.
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Polymorphism
    By Eman in forum C++ Programming
    Replies: 4
    Last Post: 10-31-2010, 06:51 AM
  2. Help with Polymorphism
    By sivapc in forum C++ Programming
    Replies: 1
    Last Post: 11-02-2009, 05:39 AM
  3. Polymorphism Help
    By forseti42 in forum C++ Programming
    Replies: 22
    Last Post: 05-07-2008, 02:12 PM
  4. polymorphism
    By slaveofthenet in forum C++ Programming
    Replies: 15
    Last Post: 07-10-2003, 11:50 AM
  5. polymorphism
    By Unregistered in forum C++ Programming
    Replies: 10
    Last Post: 12-19-2001, 12:13 AM