Path: utzoo!utgpu!water!watmath!clyde!att!osu-cis!tut.cis.ohio-state.edu!rutgers!bellcore!tness7!texbell!sugar!ficc!uunet!mcvax!ukc!cs.tcd.ie!phrrngtn From: phrrngtn@cs.tcd.ie (Paul Harrington) Newsgroups: comp.lang.c Subject: strange effects with enum types Message-ID: <143@csaran.cs.tcd.ie> Date: 13 Oct 88 23:52:08 GMT Reply-To: phrrngtn@csaran.UUCP (Paul Harrington) Organization: Computer Science Department, Trinity College, Dublin Lines: 51 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); }