Article View: comp.bugs.4bsd
Article #1215strange effects with enumerated types
From: Paul Harrington
Date: Thu, 13 Oct 1988 23:50
Date: Thu, 13 Oct 1988 23:50
52 lines
1824 bytes
1824 bytes
(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);
}
Technical Details
Message-ID:
<142@csaran.cs.tcd.ie>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!water!watmath!clyde!att!osu-cis!tut.cis.ohio-state.edu!rutgers!apple!voder!pyramid!prls!mips!wyse!vsi1!altnet!uunet!mcvax!ukc!cs.tcd.ie!phrrngtnShow Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!water!watmath!clyde!att!osu-cis!tut.cis.ohio-state.edu!rutgers!apple!voder!pyramid!prls!mips!wyse!vsi1!altnet!uunet!mcvax!ukc!cs.tcd.ie!phrrngtn From: phrrngtn@cs.tcd.ie (Paul Harrington) Newsgroups: comp.bugs.4bsd Subject: strange effects with enumerated types Keywords: enum,courier Message-ID: <142@csaran.cs.tcd.ie> Date: 13 Oct 88 23:50:12 GMT Reply-To: phrrngtn@csaran.UUCP (Paul Harrington) Organization: Computer Science Department, Trinity College, Dublin Lines: 52