SE250:HTTB:WIP:jsmi233 2

From Marks Wiki
Jump to navigation Jump to search

Generics in C

Notice how in our data structures we have a very convenient element_t symbol, so that we can change what type of data the arraylist/hashtable/whatever stores. Well thats great... but what if someone, somewhere, someday decides they want to have TWO or more array lists? Can you imagine? A program that has an array of strings AND an array of colours, for example. It seems to me that with our present way of writing data structures, the only way to do this would be to somehow write another struct and another set of functions. This screencast shows how it is possible to write a "generic" arraylist, which can take data of any type.

<html> <object type="application/x-shockwave-flash" data="http://blip.tv/scripts/flash/showplayer.swf?enablejs=true&feedurl=http%3A%2F%2Fsmth5ter%2Eblip%2Etv%2Frss&file=http%3A%2F%2Fblip%2Etv%2Frss%2Fflash%2F947319%3Freferrer%3Dblip%2Etv%26source%3D1&showplayerpath=http%3A%2F%2Fblip%2Etv%2Fscripts%2Fflash%2Fshowplayer%2Eswf" width="1000" height="700" allowfullscreen="true" id="showplayer"><param name="movie" value="http://blip.tv/scripts/flash/showplayer.swf?enablejs=true&feedurl=http%3A%2F%2Fsmth5ter%2Eblip%2Etv%2Frss&file=http%3A%2F%2Fblip%2Etv%2Frss%2Fflash%2F947319%3Freferrer%3Dblip%2Etv%26source%3D1&showplayerpath=http%3A%2F%2Fblip%2Etv%2Fscripts%2Fflash%2Fshowplayer%2Eswf" /><param name="quality" value="best" /><embed src="http://blip.tv/scripts/flash/showplayer.swf?enablejs=true&feedurl=http%3A%2F%2Fsmth5ter%2Eblip%2Etv%2Frss&file=http%3A%2F%2Fblip%2Etv%2Frss%2Fflash%2F947319%3Freferrer%3Dblip%2Etv%26source%3D1&showplayerpath=http%3A%2F%2Fblip%2Etv%2Fscripts%2Fflash%2Fshowplayer%2Eswf" quality="best" width="400" height="255" name="showplayer" type="application/x-shockwave-flash"></embed></object> </html>