🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

5 total messages Started by rmc Thu, 27 Jun 1985 18:30
Array of unions
#434
Author: rmc
Date: Thu, 27 Jun 1985 18:30
19 lines
1073 bytes
	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".
Maybe I should have known that arrays of unions don't
compile, but couldn't the compiler leave me a more
descriptive message?  I'll I'm asking for is a line
number -- that bug took me a couple of hours to locate.

			R. Martin Chavez
			(rmc@lanl.ARPA, chavez@harvard.ARPA)
Re: Array of unions
#435
Author: Doug Gwyn <gwyn>
Date: Fri, 28 Jun 1985 11:54
3 lines
738 bytes
There's nothing wrong with arrays of unions.
Perhaps either your compiler or your code is broken.
You did not give enough information for anyone to help.
Re: Array of unions
#436
Author: rmc
Date: Fri, 28 Jun 1985 15:19
45 lines
1370 bytes
> 
> 	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);
	}

			-- R. Martin Chavez
			(chavez@lanl.ARPA)
Re: Array of unions
#437
Author: Guy Harris
Date: Sat, 29 Jun 1985 04:28
10 lines
1061 bytes
> ...the C compiler bombs with "Fatal error in /lib/ccom".

That's the best it could give you; that message is the "cc" command's
cryptic way of telling you that the compiler pass whose binary is in
/lib/ccom got a signal and dumped core/MOS.  "cc" should dump the signal
name (NOT number) and an indication of whether core was dumped or not.  At
least that would give the poor user a bit better indication of what went
wrong, and might help a little bit in debugging the compiler.

	Guy Harris
Re: Array of unions
#438
Author: Joseph S. D. Yao
Date: Wed, 03 Jul 1985 01:51
44 lines
2201 bytes
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}
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads