>"Xiangliang Meng" <xi*************@hotmail.com> wrote:
Uint32 enum { a = 100; b = 200; };
NOTE: Uint32 is defined to be 'unsigned' in other source files.
In article <40****************@news.individual.net>
Richard Bos <rl*@hoekstra-uitgeverij.nl> writes:That is a syntax error. If there's a typedef in front of it, it defines
Uint32 as the enum in question ...
It is indeed a syntax error, but adding a "typedef" would not help
either, because the syntax for "typedef" is:
First, write an ordinary variable or function declarations.
int a;
char *b;
double c[2], d;
Each of these declares (and usually defines) the given identifier
as an object of the given type -- "a" has type "int", "b" has
type "char *", "c" has type "double [2]", and "d" has type
"double".
Next, stick a typedef in front:
typedef int a;
typedef char *b;
typedef double c[2], d;
(The last form is one that often surprises people.) These
change the lines from meaning "declare <name> as <object> with
type <type>" to "declare <name> as synonym for type <type>".
Hence, "a" is now a synonym for "int", "b" is now a synonym
for "char *", "c" is now a synonym for "double [2]", and "d"
is now a synonym for "double".
Now, if we do this for the "enum" above -- even after correcting
other problems like the improper semicolons -- it has the wrong
form:
/* should be: typedef <existing-type> <new-alias> */
typedef new_alias enum ...; /* wrong -- backwards! */
To give it the right form, the identifier has to come after the
"enum" sequence:
typedef enum optional_tag { a = 100, b = 200 } new_alias;
People get this backwards often, I speculate, from a perceived
(but false) symmetry with "#define":
#define DataType double /* new alias, then existing type */
typedef double DataType; /* existing type, then new alias */
Given the other syntax problems in Xiangliang Meng's original
posting, I suspect he was copying the "mystery declaration" from
(fuzzy) memory rather than the actual C source that used it.
--
In-Real-Life: Chris Torek, Wind River Systems
Salt Lake City, UT, USA (40°39.22'N, 111°50.29'W) +1 801 277 2603
email: forget about it
http://web.torek.net/torek/index.html
Reading email is like searching for food in the garbage, thanks to spammers.