Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/18/84; site hadron.UUCP Path: utzoo!watmath!clyde!bonnie!akgua!whuxlm!harpo!decvax!genrad!panda!talcott!harvard!seismo!trwatf!rlgvax!prcrs!hadron!jsdy From: jsdy@hadron.UUCP (Joseph S. D. Yao) Newsgroups: net.bugs Subject: Re: Array of unions Message-ID: <212@hadron.UUCP> Date: Tue, 2-Jul-85 21:51:22 EDT Article-I.D.: hadron.212 Posted: Tue Jul 2 21:51:22 1985 Date-Received: Fri, 5-Jul-85 06:11:53 EDT References: <27676@lanl.ARPA> <27694@lanl.ARPA> Reply-To: jsdy@hadron.UUCP (Joseph S. D. Yao) Distribution: net Organization: Hadron, Inc., Fairfax, VA Lines: 44 In article <27694@lanl.ARPA> rmc@lanl.ARPA writes: >> I defined an array of unions as follows: >> typedef union { >> unsigned char *bytes; >> unsigned long *words; >> } block; >> block sched[NKEYS]; >> Now if I try to pass sched[i] as a parameter, >> the C compiler bombs with "Fatal error in /lib/ccom". > Here's an example of a program that didn't >compile under 4.2/4.3bsd (VAX). The program DID >compile on a SUN, or with the portable C compiler >under SUMacC. >#define NKEYS 20 > typedef union { > unsigned char *bytes; unsigned long *words; > } block; > main() > { > block sched[NKEYS]; int i; > i= 4; bar(i, sched); > } > > bar (i, sched) block sched[]; > { foo(sched[i]); } > > foo (junk) block junk; > { printf("%d\n",junk.bytes); } As others have said, this should have worked. Potential problems/ perturbations to test: (1) in bar(), try changing sched[] to *sched. As discussed ad infinauseum elsewhere, this s h o u l d make no difference. (2) in bar(), pass &sched[i]; and in foo(), declare block *junk;. Also, of course, junk->bytes. The construct you use there is relatively recent, and might cause problems that haven't been encountered before. I know that passing structs as parameters is now old hat, but I think some compilers handle unions a little strangely. Addresses (as in the old days) might be a bit better. Good luck. Write if it's found to work. -- Joe Yao hadron!jsdy@seismo.{ARPA,UUCP}