Bruno Haible <[EMAIL PROTECTED]> wrote:

> Jim Meyering wrote:
>> Why not use an enum, as you suggested above?
>>
>>   enum { CUTOFF = 1024 };
>>   char buf[CUTOFF];
>
> That works only for 'int' constants, not for 'unsigned int' or 'long'.

Good.  So, for small ("int"-sized) constants like the above,
there's no problem.

> Also, HP-UX and AIX compilers are known to have bugs in this area. (See
> lib/malloca.h.)
>
> Also, the use of 'enum' to define constants is likely to surprise people,
> since - while technically correct according to ANSI C - it is not the
> mainstream style.

If everyone used that argument, new, more-useful paradigms
would never make it into common usage.
IMHO, using "enum" for such constants deserves to be more mainstream.
Some people might even be _pleasantly_ surprised.

>> Pádraig and I were discussing that in the context of coreutils'
>> new truncate.c.  I'd like to be able to use the attribute
>> (though not for cases like the above, where enum is fine)
>> to mark variables as write-once.
>
> There is no portability problem with that, as far as I know. gcc versions
> around gcc-2.6 had problems with 'const' arrays, but that's more than 10
> years ago.

Oh!  I misunderstood.
Good!


Reply via email to