title: Is it possible to use #define inside a function?
body: <p>For example, I saw source code like the following. Can we use <code>#define</code> in a function? How does it work? (more information: this code is what I copied from <code>openvswitch</code> source code):</p>
  <pre><code>void *
  ofputil_put_action(enum ofputil_action_code code, struct ofpbuf *buf)
  {
  switch (code) {
  case OFPUTIL_ACTION_INVALID:
  
  #define OFPAT13_ACTION(ENUM, STRUCT, EXTENSIBLE, NAME) case OFPUTIL_##ENUM:
  #include &quot;ofp-util.def&quot;
      OVS_NOT_REACHED();
  
  #define OFPAT10_ACTION(ENUM, STRUCT, NAME)                  \
  case OFPUTIL_##ENUM: return ofputil_put_##ENUM(buf);
  #define OFPAT11_ACTION(ENUM, STRUCT, EXTENSIBLE, NAME)      \
  case OFPUTIL_##ENUM: return ofputil_put_##ENUM(buf);
  #define NXAST_ACTION(ENUM, STRUCT, EXTENSIBLE, NAME)        \
  case OFPUTIL_##ENUM: return ofputil_put_##ENUM(buf);
  #include &quot;ofp-util.def&quot;
  }
  OVS_NOT_REACHED();
  }
  
  #define OFPAT10_ACTION(ENUM, STRUCT, NAME)                        \
  void                                                        \
  ofputil_init_##ENUM(struct STRUCT *s)                       \
  {                                                           \
      memset(s, 0, sizeof *s);                                \
      s-&gt;type = htons(ENUM);                                  \
      s-&gt;len = htons(sizeof *s);                              \
  }                                                           \
                                                              \
  struct STRUCT *                                             \
  ofputil_put_##ENUM(struct ofpbuf *buf)                      \
  {                                                           \
      struct STRUCT *s = ofpbuf_put_uninit(buf, sizeof *s);   \
      ofputil_init_##ENUM(s);                                 \
      return s;                                               \
  }
  #define OFPAT11_ACTION(ENUM, STRUCT, EXTENSIBLE, NAME) \
  OFPAT10_ACTION(ENUM, STRUCT, NAME)
  #define OFPAT13_ACTION(ENUM, STRUCT, EXTENSIBLE, NAME) \
  OFPAT10_ACTION(ENUM, STRUCT, NAME)
  #define NXAST_ACTION(ENUM, STRUCT, EXTENSIBLE, NAME)            \
  void                                                        \
  ofputil_init_##ENUM(struct STRUCT *s)                       \
  {                                                           \
      memset(s, 0, sizeof *s);                                \
      s-&gt;type = htons(OFPAT10_VENDOR);                        \
      s-&gt;len = htons(sizeof *s);                              \
      s-&gt;vendor = htonl(NX_VENDOR_ID);                        \
      s-&gt;subtype = htons(ENUM);                               \
  }                                                           \
                                                              \
  struct STRUCT *                                             \
  ofputil_put_##ENUM(struct ofpbuf *buf)                      \
  {                                                           \
      struct STRUCT *s = ofpbuf_put_uninit(buf, sizeof *s);   \
      ofputil_init_##ENUM(s);                                 \
      return s;                                               \
  }
  #include &quot;ofp-util.def&quot;
  </code></pre>