Re: K&R2, exercise 6.4

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Keith Thompson

    Re: K&R2, exercise 6.4

    arnuld <sunrise@see.si gs.invalidwrite s:
    >On Wed, 07 May 2008 09:35:13 +0500, arnuld wrote:
    >
    >okay I have edited it a little bit.
    [snip]
    enum MAXSIZE { ARRSIZE = 1000, WORDSIZE = 30 };
    [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"
  • arnuld

    #2
    Re: K&amp;R2, exercise 6.4

    On Tue, 06 May 2008 00:43:33 -0700, Keith Thompson wrote:

    I'd just do this:
    enum { ARRSIZE = 1000, WORDSIZE = 30 };
    ...SNIP...
    You're never going to use the type; making it anonymous makes that
    clear.
    thanks for the tip :)


    --

    my email ID is @ the above blog.
    just check the "About Myself" page :)

    Comment

    Working...