arnuld <sunrise@see.si gs.invalidwrite s:
>
[snip]
[snip]
You're using the "enum trick" (a name I just invented for it) to
declare ARRSIZE and WORDSIZE as constants. I have no objection to
that, but why give the enum type a name? You never use the identifier
MAXSIZE in the rest of your program.
I'd just do this:
enum { ARRSIZE = 1000, WORDSIZE = 30 };
or perhaps this:
enum { ARRSIZE = 1000 };
enum { WORDSIZE = 30 };
You're never going to use the type; making it anonymous makes that
clear.
(This construct, in either form, is a blatant abuse of the "enum"
construct. It's not what it was intended to be used for. It creates
a type, only to discard it and use only the constants that are created
along with it, almost as a side effect. It's limited to values of
type int. But it's a cool trick anyway.)
--
Keith Thompson (The_Other_Keit h) <kst-u@mib.org>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
>On Wed, 07 May 2008 09:35:13 +0500, arnuld wrote:
>okay I have edited it a little bit.
enum MAXSIZE { ARRSIZE = 1000, WORDSIZE = 30 };
You're using the "enum trick" (a name I just invented for it) to
declare ARRSIZE and WORDSIZE as constants. I have no objection to
that, but why give the enum type a name? You never use the identifier
MAXSIZE in the rest of your program.
I'd just do this:
enum { ARRSIZE = 1000, WORDSIZE = 30 };
or perhaps this:
enum { ARRSIZE = 1000 };
enum { WORDSIZE = 30 };
You're never going to use the type; making it anonymous makes that
clear.
(This construct, in either form, is a blatant abuse of the "enum"
construct. It's not what it was intended to be used for. It creates
a type, only to discard it and use only the constants that are created
along with it, almost as a side effect. It's limited to values of
type int. But it's a cool trick anyway.)
--
Keith Thompson (The_Other_Keit h) <kst-u@mib.org>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Comment