Sunday, August 26, 2007

polymorphism in C

Even polymorphism can by implemented in C. Polymorphism in Java and C++ is implemented by associating with each instance a table of functions. Polymorphic method names are converted to indexes into this function table. When a method call on a particular instance is executed, the function table for that instance (actually these tables are shared among the instances of a class), used to find the proper function to execute.

Since C has the ability to store pointers for functions as a basic data type, and the ability to calla function from such a function pointer. It is straightforward (though not always fun) to explicitly duplicate the function table mechanism and implement polymorphisms by hand.

Al

1 comment:

. h a y l . said...

hi i was wondering if you'd be interested in checking out my websites

http://stay-home-and-earn-online.blogspot.com/

and

http://stayhomeandearn.blogspot.com

i would really appreciate if you checked them out.
no commitments and no viruses. i promise.
thank you so much. =)

i would be very grateful if you linked me!