小编CCo*_*der的帖子

使用ENUM作为位图,如何在C中验证

我正在为具有内存限制的嵌入式应用程序开发固件.我有一组需要在收到时处理的命令.每个命令都属于不同的"桶",每个"桶"都有一系列有效的命令号.我创建了两个ENUM,如下所示,以实现此目的.

enum
{
  BUCKET_1 = 0x100, // Range of 0x100 to 0x1FF
  BUCKET_2 = 0x200, // Range of 0x200 to 0x2FF
  BUCKET_3 = 0x300, // Range of 0x300 to 0x3FF
  ...
  ...
  BUCKET_N = 0xN00 // Range of 0xN00 to 0xNFF
} cmd_buckets;

enum 
{
  //BUCKET_1 commands
  CMD_BUCKET_1_START = BUCKET_1,
  BUCKET_1_CMD_1,
  BUCKET_1_CMD_2,
  BUCKET_1_CMD_3,
  BUCKET_1_CMD_4,
  //Add new commands above this line
  BUCKET_1_CMD_MAX,

  //BUCKET_2 commands
  CMD_BUCKET_2_START = BUCKET_2,
  BUCKET_2_CMD_1,
  BUCKET_2_CMD_2,
  BUCKET_2_CMD_3,
  //Add new commands above this line
  BUCKET_2_CMD_MAX,

  //BUCKET_3 commands
  ...
  ... …
Run Code Online (Sandbox Code Playgroud)

c embedded enums bitmap c-preprocessor

5
推荐指数
1
解决办法
185
查看次数

标签 统计

bitmap ×1

c ×1

c-preprocessor ×1

embedded ×1

enums ×1