"Generic" Data

Dick Grune dick at tjalk.UUCP
Tue Dec 10 08:33:16 AEST 1985


In article <10200027 at ada-uts.UUCP> richw at 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



More information about the Comp.lang.c mailing list