Newsgroups: comp.lang.c Path: utzoo!henry From: henry@utzoo.uucp (Henry Spencer) Subject: Re: Passing types to a subroutine Message-ID: <1988Nov11.183710.22545@utzoo.uucp> Organization: U of Toronto Zoology References: <14457@mimsy.UUCP> Date: Fri, 11 Nov 88 18:37:10 GMT In article <14457@mimsy.UUCP> sjr@mimsy.UUCP (Stephen J. Roznowski) writes: > float a[100]; > subroutine(...., a[100], ...); > > double a[100]; > subroutine(...., a[100], ...); > >and have the subroutine do the right thing with a[]. >How do you pass the knowledge of the array type to the >subroutine? I need to be able to pass the knowledge >that the array a[] is either float or double (or for >that matter unsign int). You can't do this in C. A function parameter has to have a single, specific type at compile time; you don't get to postpone the decision to run time. The best you can do is a complicated little dance with unions and pointers, which isn't really any simpler than just writing three versions of your subroutine, one for each type. -- Sendmail is a bug, | Henry Spencer at U of Toronto Zoology not a feature. | uunet!attcan!utzoo!henry henry@zoo.toronto.edu