C中的宏不可理解

时间:2015-10-02 05:48:22

标签: c linux macros

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

#define INIT_C_CC "\003\034\177\025\004\0\1\0\021\023\032\0\022\017\027\026\0"

我不明白这是什么意思?这不是逃避/八进制/我可以轻易找到的任何东西。请帮忙。

2 个答案:

答案 0 :(得分:5)

这个宏定义了一组特殊字符,用于初始化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

  

c_cc数组定义终端特殊字符。象征性的          index(初始值)和含义是:

   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.

答案 1 :(得分:1)

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

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

char c_cc[17] = "\003\034\177\025\004\0\1\0\021\023\032\0\022\017\027\026\0";

相当于

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