tech-kern archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: Do all -current compilers support C23 typed enum syntax?



> For example:

>     typedef enum : int {
>             subsys_thing_a = 0,
>             subways_thing_b,
>     } subsys_thing_t;

>     int subsys_call(subsys_thing_t thing);

What benefit does this bring?  enum constants have historically been
ints (I don't _like_ this - it feels to me like conceptual type
confusion - but it's how they've worked), so, unless you anticipate
wanting an argument that is smaller or larger than int, I see no value
in attaching a specific type to it.  Even if you do, all you need is to
document the argument as having its actual type.  The only real
difference I see between

	enum {
		FOO = 1,
		BAR,
		BAZ,
	};

and

	#define FOO 1
	#define BAR 2
	#define BAZ 3

is that they obey different scope rules.  You can pass either one to an
argument of any integral type just fine (well, possibly except _Bool).

What am I missing?

/~\ The ASCII				  Mouse
\ / Ribbon Campaign
 X  Against HTML		mouse%rodents-montreal.org@localhost
/ \ Email!	     7D C8 61 52 5D E7 2D 39  4E F1 31 3E E8 B3 27 4B


Home | Main Index | Thread Index | Old Index