Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!csd4.milw.wisc.edu!lll-winken!uunet!mcvax!hp4nl!eutrc3!wzv!wietse From: wietse@wzv.UUCP (Wietse Z. Venema) Newsgroups: comp.lang.c++ Subject: Re: Can I hide data from my compiler? Message-ID: <257@wzv.UUCP> Date: 27 Mar 89 22:46:53 GMT References: <10133@bloom-beacon.MIT.EDU> Reply-To: wietse@wzv.UUCP (Wietse Z. Venema) Organization: Eindhoven University of Technology, The Netherlands Lines: 30 In article <10133@bloom-beacon.MIT.EDU> sorensen@hstbme.mit.edu.UUCP (Gregory Sorensen) writes: > >My problem: I'd like to hide my data type from my routines. >Specifically, I'd like routines which I can pass a data object >made up of, say, floats or shorts, and use the same identical >code to process either, although I won't know _until run time_ >whether the data is made up of floats or shorts. Is there a way >to do this other than defining functions for each data object? Once upon a time I did something like that (not in C++, however, just in plain C). It began as a set of printf()/scanf() functions for C structs. A data structure was described by a format string, such as f[10] array of 10 floats {dff} structure with one int and two floats and so on. The implementation involved numerous pointer casts, as you may expect, and some knowledge about the alignment properties of code generated by the compiler. This worked fine for simple data structures such as arrays, vectors and other tables. Support for self-referential types (linked lists or trees) was never implemented. Another approach would be to mechanically generate the proper read- write functions from the data declarations themselves. This idea was expressed last October by Eric Raymond . Perhaps he can comment on the status of this approach. -- work: wswietse@eutrc3.uucp | Eindhoven University of Technology work: wswietse@heitue5.bitnet | Mathematics and Computing Science home: wietse@wzv.uucp | 5600 MB Eindhoven, The Netherlands