C 中的宏无法理解

Macro in C not understandable

我正在查看 linux 系统中的头文件。它有一个宏定义为:

#define INIT_C_CC "[=10=]3475[=10=]4[=10=][=10=]132[=10=]2776[=10=]"

我不明白这是什么意思?这不是我可以轻易找到的 escape/octal/anything。请帮忙。

这个宏定义了一组特殊字符,用于初始化termios结构中的cc数组。在 termios 手册页中你可以看到它们的含义:

宏是八进制表示的字符序列。 https://en.wikipedia.org/wiki/Escape_sequences_in_C

在这里你可以找到八进制表示代码的ascii:https://courses.engr.illinois.edu/ece390/books/labmanual/ascii-code-table.html

发件人:http://man7.org/linux/man-pages/man3/termios.3.html

The c_cc array defines the terminal special characters. The symbolic indices (initial values) and meaning are:

   VDISCARD
          (not in POSIX; not supported under Linux; 017, SI, Ctrl-O)
          Toggle: start/stop discarding pending output.  Recognized when
          IEXTEN is set, and then not passed as input.

   VDSUSP (not in POSIX; not supported under Linux; 031, EM, Ctrl-Y)
          Delayed suspend character (DSUSP): send SIGTSTP signal when
          the character is read by the user program.  Recognized when
          IEXTEN and ISIG are set, and the system supports job control,
          and then not passed as input.

   VEOF   (004, EOT, Ctrl-D) End-of-file character (EOF).  More
          precisely: this character causes the pending tty buffer to be
          sent to the waiting user program without waiting for end-of-
          line.  If it is the first character of the line, the read(2)
          in the user program returns 0, which signifies end-of-file.
          Recognized when ICANON is set, and then not passed as input.

   VEOL   (0, NUL) Additional end-of-line character (EOL).  Recognized
          when ICANON is set.

   VEOL2  (not in POSIX; 0, NUL) Yet another end-of-line character
          (EOL2).  Recognized when ICANON is set.

   VERASE (0177, DEL, rubout, or 010, BS, Ctrl-H, or also #) Erase
          character (ERASE).  This erases the previous not-yet-erased
          character, but does not erase past EOF or beginning-of-line.
          Recognized when ICANON is set, and then not passed as input.

   VINTR  (003, ETX, Ctrl-C, or also 0177, DEL, rubout) Interrupt
          character (INTR).  Send a SIGINT signal.  Recognized when ISIG
          is set, and then not passed as input.

   VKILL  (025, NAK, Ctrl-U, or Ctrl-X, or also @) Kill character
          (KILL).  This erases the input since the last EOF or
          beginning-of-line.  Recognized when ICANON is set, and then
          not passed as input.

   VLNEXT (not in POSIX; 026, SYN, Ctrl-V) Literal next (LNEXT).  Quotes
          the next input character, depriving it of a possible special
          meaning.  Recognized when IEXTEN is set, and then not passed
          as input.

   VMIN   Minimum number of characters for noncanonical read (MIN).

   VQUIT  (034, FS, Ctrl-\) Quit character (QUIT).  Send SIGQUIT signal.
          Recognized when ISIG is set, and then not passed as input.

   VREPRINT
          (not in POSIX; 022, DC2, Ctrl-R) Reprint unread characters
          (REPRINT).  Recognized when ICANON and IEXTEN are set, and
          then not passed as input.

   VSTART (021, DC1, Ctrl-Q) Start character (START).  Restarts output
          stopped by the Stop character.  Recognized when IXON is set,
          and then not passed as input.

   VSTATUS
          (not in POSIX; not supported under Linux; status request: 024,
          DC4, Ctrl-T).  Status character (STATUS).  Display status
          information at terminal, including state of foreground process
          and amount of CPU time it has consumed.  Also sends a SIGINFO
          signal (not supported on Linux) to the foreground process
          group.

   VSTOP  (023, DC3, Ctrl-S) Stop character (STOP).  Stop output until
          Start character typed.  Recognized when IXON is set, and then
          not passed as input.

   VSUSP  (032, SUB, Ctrl-Z) Suspend character (SUSP).  Send SIGTSTP
          signal.  Recognized when ISIG is set, and then not passed as
          input.

   VSWTCH (not in POSIX; not supported under Linux; 0, NUL) Switch
          character (SWTCH).  Used in System V to switch shells in shell
          layers, a predecessor to shell job control.

   VTIME  Timeout in deciseconds for noncanonical read (TIME).

   VWERASE
          (not in POSIX; 027, ETB, Ctrl-W) Word erase (WERASE).
          Recognized when ICANON and IEXTEN are set, and then not passed
          as input.

   An individual terminal special character can be disabled by setting
   the value of the corresponding c_cc element to _POSIX_VDISABLE.

   The above symbolic subscript values are all different, except that
   VTIME, VMIN may have the same value as VEOL, VEOF, respectively.  In
   noncanonical mode the special character meaning is replaced by the
   timeout meaning.  For an explanation of VMIN and VTIME, see the
   description of noncanonical mode below.

INIT_C_CC 宏的替换文本是字符串文字,其中每个字符都指定为八进制转义序列。

如果用于初始化数组,则扩展为

char c_cc[17] = "[=10=]3475[=10=]4[=10=][=10=]132[=10=]2776[=10=]";

相当于

char c_cc[17] = {3, 28, 127, 21, 4, 0, 1, 0, 17, 19, 26, 0, 18, 15, 23, 22, 0 };