Passing types to a subroutine
Doug Gwyn
gwyn at smoke.BRL.MIL
Fri Nov 11 02:59:12 AEST 1988
In article <14457 at mimsy.UUCP> sjr at mimsy.UUCP (Stephen J. Roznowski) writes:
> float a[100];
> subroutine(...., a[100], ...);
> double a[100];
> subroutine(...., a[100], ...);
>subroutine(....,array,....)
>[???] *array;
>How do you pass the knowledge of the array type to the
>subroutine?
You don't. Types are dealt with at compile time, not run time.
It is in fact possible for a pointer-to-float to be passed
differently than a pointer-to-double.
If you REALLY have to do this, consider casting the arguments
(which should be "a", not "a[100]") to type pointer-to-void or
pointer-to-char, and add another parameter to the subroutine
that can be used to indicate how to "un-cast" the funny
parameter. The code for this won't be clean..
More information about the Comp.lang.c
mailing list