Passing types to a subroutine

Doug Gwyn gwyn at smoke.BRL.MIL
Tue Nov 15 16:33:28 AEST 1988


In article <14548 at mimsy.UUCP> sjr at mimsy.umd.edu.UUCP (Stephen J. Roznowski) writes:
>The problem is that I can't determine the array type
>at compile time.  These subroutines are going to be part of
>a library.

The technique I suggested will work, although you might be better off
with separate functions to operate on different data types.

>And you are right that the pointers may be different,
>or at least have different alignment properties. Is this
>true of the pointer-to-void or pointer-to-char?

Any pointer type can be cast to either pointer-to-char or (if you have
it) pointer-to-void as a "canonical" pointer type to be passed through
a function parameter knothole having definite type, and inside the
function the conversion can be done in the reverse direction.  You
need to have additional information as to which type to convert back
to; this bit of information can be passed via another parameter.

If you can figure out how to avoid having a function with such a
messy interface, you'd be better off.



More information about the Comp.lang.c mailing list