lkml.org 
[lkml]   [2005]   [Dec]   [2]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: Use enum to declare errno values
Coywolf Qi Hunt wrote:
> 2005/12/2, Pekka Enberg <penberg@cs.helsinki.fi>:
>
>>Hi,
>>
>>2005/12/2, Denis Vlasenko <vda@ilport.com.ua>:
>>
>>>>There is another reason why enums are better than #defines:
>>
>>On 12/2/05, Coywolf Qi Hunt <coywolf@gmail.com> wrote:
>>
>>>This is a reason why enums are worse than #defines.
>>>
>>>Unlike in other languages, C enum is not much useful in practices.
>>>Maybe the designer wanted C to be as fancy as other languages? C
>>>shouldn't have had enum imho. Anyway we don't have any strong motives
>>>to switch to enums.
>>
>>I don't follow your reasoning. The naming collision is a real problem
>>with macros. With enum and const, the compiler can do proper checking
>>with meaningful error messages. Please explain why you think #define
>>is better for Denis' example?
>>
>> Pekka
>>
>
>
> That is a bad bad style. It should be `#define FOO 123' if you have to
> write it.
>
> It's also hard to see what the confusing bar is "if you are looking at
> file.c alone".
>
> enum is worse than typdef. Don't you see why we should use `struct
> task_struct', rather than `task_t'?
>
> Introducing enum alone can't solve the problems from bad macro usage
> habits. Actually, it's not anything wrong with macros, it's
> programers' bad coding style.

Using enum doesn't *solve* problems, it does *allow* type checking, and
*prevent* namespace pollution. Use of typedef allows future changes, if
you use "struct XXX" you're stuck with it.

--
bill davidsen <davidsen@tmr.com>
CTO TMR Associates, Inc
Doing interesting things with small computers since 1979
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

\
 
 \ /
  Last update: 2005-12-02 16:53    [W:0.084 / U:0.068 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site