一、指定的初始化

  1. int fibs[] = {1, 1, 2, 3, 5};

二、数组

  1. /* Entries may not correspond to actual numbers. Some entries omitted. */
  2. #define EINVAL 1
  3. #define ENOMEM 2
  4. #define EFAULT 3
  5. /* ... */
  6. #define E2BIG 7
  7. #define EBUSY 8
  8. /* ... */
  9. #define ECHILD 12
  10. /* ... */

现在,假设我们想为每个错误码提供一个错误描述的字符串。
为了确保数组保持了最新的定义,无论头文件做了任何修改或增补,我们都可以用这个数组指定的语法

  1. char *err_strings[] = {
  2. [0] = "Success",
  3. [EINVAL] = "Invalid argument",
  4. [ENOMEM] = "Not enough memory",
  5. [EFAULT] = "Bad address",/* ... */
  6. [E2BIG ] = "Argument list too long",
  7. [EBUSY ] = "Device or resource busy",/* ... */
  8. [ECHILD] = "No child processes"/* ... */
  9. };

三、结构体与联合体

  1. struct point {int x;int y;int z;}
  2. struct point p = {
  3. .x = 3,
  4. .y = 4,
  5. .z = 5
  6. };

四、宏列表

**

  1. #define FLAG_LIST(_) \
  2. _(InWorklist) \
  3. _(EmittedAtUses) \
  4. _(LoopInvariant) \
  5. _(Commutative) \
  6. _(Movable) \
  7. _(Lowered) \
  8. _(Guard)