【问题标题】:Does C99 permit universal character names in identifiers?C99 是否允许在标识符中使用通用字符名称?
【发布时间】:2015-01-20 05:00:47
【问题描述】:

来自 C99 规范的 WG14/N1124 草案的 §6.4.2,“标识符”:

identifier:  
       identifier-nondigit  
       identifier identifier-nondigit  
       identifier digit

identifier-nondigit:  
       nondigit  
       universal-character-name  
       other implementation-defined characters

以及第 6.4.3 节,“通用字符名称”:

universal-character-name:
       \u hex-quad
       \U hex-quad hex-quad

这似乎表明像foo\u00AAbar 这样的标识符根据语法是有效的。我在语义中找不到任何其他暗示的东西。然而 GCC 拒绝了这样的标识符,甚至没有尝试解析它:

<stdin>:2: error: stray ‘\’ in program
<stdin>:2: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘u00AAbar’
<stdin>:2: error: ‘u00AAbar’ undeclared (first use in this function)

这是对 GCC、C99 标准的疏忽还是我的推理?

【问题讨论】:

    标签: c language-lawyer c99


    【解决方案1】:

    这三个都不是。它只是一个长期未实现(或者更确切地说,只是部分实现)的功能。它最近完成了,将在 GCC 5 中可用。在该版本之前,您可以使用-fextended-identifiers 命令行选项,但在某些情况下它出错了导致它默认不启用。

    您可以在Status of C99 features in GCC 上看到此列表。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-02-18
      • 1970-01-01
      • 2011-06-15
      • 2017-05-07
      • 1970-01-01
      • 2015-07-14
      相关资源
      最近更新 更多