strange effects with enumerated types

Paul Harrington phrrngtn at cs.tcd.ie
Fri Oct 14 09:50:12 AEST 1988


(I tried posting this before but it did not arrive)
The following code was tested on a SUN 3/50 under SunOS 3.3.
Depending on wheter you give an initialiser to the enum elements in the
declaration of the type of p or not you get very different outputs from
test_fn() ranging from 1,3,5 to 1,2,4 to 2,4,6 with my old favourite 2,3,4 when
you say a=1,b=2,c=3 in the declaration of the type of p in test_fn()

An RPC package called Courier generates this unusual type of code with
parameter types being redeclared  even for functions that have the same
effective types for their parameters.

why does the compiler (I don't know which compiler it is. I assume it is
the standard one supplied with a SUN 3/50) produce this result and is it a bug of this compiler or a "feature" of C ?





typedef struct {
	enum{a=1,b,c}choice;
	union{
	int a;
	long b;
	short c;
	}u;
	}new_struct;

typedef enum {e,f,g,h} e1;


void test_fn1(p)
struct {
	enum{a=1,b=2,c=3}choice;
	union{
	int a;
	long b;
	short c;
	}u;
	}*p;
{
printf("the size of p is %d\n",sizeof(p));
printf("(test_fn1) a=%d,b=%d,c=%d\n",a,b,c);
}

main()
{
new_struct *v;
printf("(main) a=%d,b=%d,c=%d\n",a,b,c);
printf("the size of e1 is %d\n",sizeof(e1));
printf("the size of a is %d\n",sizeof(a));
test_fn1(v);
}



More information about the Comp.bugs.4bsd.ucb-fixes mailing list