【问题标题】:Macro in C not understandableC 中的宏无法理解
【发布时间】:2015-10-02 05:48:22
【问题描述】:

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

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

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

【问题讨论】:

  • 究竟是哪个头文件?可能你可以在文件中搜索INIT_C_CC 以了解它的使用更好。
  • @rootkea,我第一次引用的只是这个,你也可以看看这个。 lxr.oss.org.cn/plain/source/arch/cris/include/asm/…
  • 回复:“这不是 [...]/八进制”:当然是。是什么让你认为它不是?
  • 很明显八进制的。
  • 缺少比7 更大的东西会泄露它吗?

标签: c linux macros


【解决方案1】:

该宏定义了一组特殊字符,用于初始化 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 数组定义了终端特殊字符。象征性的 索引(初始值)和含义是:

   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,这是什么意思?该变量现在有什么值?
  • 这是一个八进制表示的字符序列。 en.wikipedia.org/wiki/Escape_sequences_in_C
【解决方案2】:

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 };

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-01-27
    • 2023-03-16
    • 2013-09-16
    • 2014-01-21
    • 1970-01-01
    • 1970-01-01
    • 2023-02-06
    • 1970-01-01
    相关资源
    最近更新 更多