1、用enum关键字说明常量(即说明枚举常量)有以下几点好处:
(1) 使程序更容易维护和直观。例如,下面定义的枚举是描述UART支持的传输bit位数,从枚举类型的定义就可以知道UART模块提供的传输bit的几种模式。
enum
{
usartDatabits4 = USART_FRAME_DATABITS_FOUR, /* 4 databits (not available for UART). */
usartDatabits5 = USART_FRAME_DATABITS_FIVE, /**< 5 databits (not available for UART). */
usartDatabits6 = USART_FRAME_DATABITS_SIX, /**< 6 databits (not available for UART). */
usartDatabits7 = USART_FRAME_DATABITS_SEVEN, /**< 7 databits (not available for UART). */
usartDatabits8 = USART_FRAME_DATABITS_EIGHT, /**< 8 databits. */
usartDatabits9 = USART_FRAME_DATABITS_NINE, /**< 9 databits. */
usartDatabits10 = USART_FRAME_DATABITS_TEN, /**< 10 databits (not available for UART). */
} USART_Databits_Enum;
|