Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.1 6/24/83 (MC840302); site tjalk.UUCP Path: utzoo!linus!philabs!cmcl2!seismo!mcvax!vu44!botter!tjalk!dick From: dick@tjalk.UUCP (Dick Grune) Newsgroups: net.lang.c Subject: Re: "Generic" Data Message-ID: <534@tjalk.UUCP> Date: Mon, 9-Dec-85 17:33:16 EST Article-I.D.: tjalk.534 Posted: Mon Dec 9 17:33:16 1985 Date-Received: Wed, 11-Dec-85 21:45:59 EST References: <10200027@ada-uts.UUCP> Reply-To: dick@tjalk.UUCP (Dick Grune) Organization: VU Informatica, Amsterdam Lines: 38 Keywords: packages, instantiation, APSE In article <10200027@ada-uts.UUCP> richw@ada-uts.UUCP writes: > >Does anybody have any ideas for how one could implement "generic" >data types in C? The term generic is borrowed from Ada; > .......... >Other ideas which use (ab-use?) the C preprocessor are possible, >but are much more involved. > >-- Rich Wagner Yes, you can do a lot of things that way, and, if you're willing to put up with Ada's long-windedness, you can even make it look nice. After all, instantiating a package with given parameters in Ada is like compiling in C with a given set of #defines in an #include file. I've been experimenting with such trickery, just because I wanted types and functions (real functions, not some int (*signal())() or so) in C, and no duplicate code, and have it look nice to boot. One important trick turns out to be to also instantiate the *.h file to be used with the instantiated package. (Why is it that sentences about Ada are twice as complicated as normal language? Why is it that articles about Ada are twice ... etc.?) Also, make is quite cooperative in playing the APSE role. I am presently summing it all up in a small article for SIGPLAN Notices which I hope to finish between Christmas and New Year's Day (all scientific work is done when honest people sleep or eat turkey). If you are interested, I can send you a sample program in this technique, but it's too long to just post it (over 200 lines, and that's minimum. Why is it that anything concerning Ada is twice ...?) Dick Grune Vrije Universiteit de Boelelaan 1081 1081 HV Amsterdam the Netherlands