f



C programmers! How do you use your 'enum's ?

Dear mates,

This is just a small survey for the common (and uncommon) nontrivial
uses of the aforementioned C construct.
It's posted by an average C programmer who's curious about how his
elder colleagues utilize this feature of C in their implementations
based on diverse programming styles in diverse application domains.

Thank you for your interest.

Best regards,
//rk
0
8/7/2003 9:30:02 PM
comp.lang.c 30656 articles. 5 followers. spinoza1111 (3246) is leader. Post Follow

4 Replies
538 Views

Similar Articles

[PageSpeed] 40

Razmig K <strontium90@postmaster.co.uk> wrote:
> Dear mates,
> 
> This is just a small survey for the common (and uncommon) nontrivial
> uses of the aforementioned C construct.
> It's posted by an average C programmer who's curious about how his
> elder colleagues utilize this feature of C in their implementations
> based on diverse programming styles in diverse application domains.

I used enums once, found them not much useful and never used them
again. I think I could be persuaded to use them though if someone would
provide some good arguments.
0
drahflow (6)
8/7/2003 10:39:11 PM
On 7 Aug 2003 14:30:02 -0700, strontium90@postmaster.co.uk (Razmig K)
wrote:

>Dear mates,
>
>This is just a small survey for the common (and uncommon) nontrivial
>uses of the aforementioned C construct.
>It's posted by an average C programmer who's curious about how his
>elder colleagues utilize this feature of C in their implementations
>based on diverse programming styles in diverse application domains.

I don't know what you consider a non-trivial use ;-)

I use them when I need a number of related symbolic constants with
defined values, for example the states in a state machine. I prefer
enums rather than lists of defines.

--
Al Balmer
Balmer Consulting
removebalmerconsultingthis@att.net
0
albalmer (2312)
8/7/2003 10:54:48 PM
In 'comp.lang.c', strontium90@postmaster.co.uk (Razmig K) wrote:

> It's posted by an average C programmer who's curious about how his
> elder colleagues utilize this feature of C in their implementations
> based on diverse programming styles in diverse application domains.

I'm used to use enums in many occasions. 

- 'Automatic' enums

The values are for internal use. They only must be different :

typedef enum
{
   MODULE_A_FUNCTION_A_VALUE_A,
   MODULE_A_FUNCTION_A_VALUE_B,
   MODULE_A_FUNCTION_A_VALUE_C,
   MODULE_A_FUNCTION_A_NB
}
module_a_function_a_e;

e.g.: 

typedef enum
{
   LED_STS_OFF,
   LED_STS_ON,
   LED_STS_BLINK,
   LED_STS_NB
}
led_sts_e;

- 'Manual' enums

The values have been defined by some interface document.

typedef enum
{
   MODULE_B_FUNCTION_A_VALUE_A = 123,
   MODULE_B_FUNCTION_A_VALUE_B = 456,
   MODULE_B_FUNCTION_A_VALUE_C = 789,
   MODULE_B_FUNCTION_A_dummy
}
module_b_function_a_e;

e.g.: 

typedef enum
{
   RECORD_SIZE_NAME = 32,
   RECORD_SIZE_ADDRESS = 128,
   RECORD_SIZE_CITY = 32,
   RECORD_SIZE_dummy
}
record_size_e;

-- 
-ed- emdelYOURBRA@noos.fr [remove YOURBRA before answering me]
The C-language FAQ: http://www.eskimo.com/~scs/C-faq/top.html
<blank line>
FAQ de f.c.l.c : http://www.isty-info.uvsq.fr/~rumeau/fclc/
0
emdelYOURBRA (457)
8/7/2003 10:54:48 PM
On 7 Aug 2003 14:30:02 -0700, strontium90@postmaster.co.uk (Razmig K)
wrote:

>Dear mates,
>
>This is just a small survey for the common (and uncommon) nontrivial
>uses of the aforementioned C construct.
>It's posted by an average C programmer who's curious about how his
>elder colleagues utilize this feature of C in their implementations
>based on diverse programming styles in diverse application domains.
>
You might be interested in this article by Don Saks, and the four
other articles referenced at the end of it.

http://www.embedded.com/showArticle.jhtml;jsessionid=4FNUWJFMRBXCKQSNDBGCKHSCJUMEKJVN?articleID=12803561

--
Al Balmer
Balmer Consulting
removebalmerconsultingthis@att.net
0
albalmer (2312)
8/7/2003 10:58:43 PM
Reply: