草庐IT

c++ - C11 编译。翻译阶段 #1 和 #5。通用字符名称

coder 2024-02-22 原文

我试图理解 C11 标准中的通用字符名称,发现 C11 标准的 N1570 草案在翻译阶段 1 和 5 以及 UCN 的形成和处理方面比 C++11 标准要少得多他们。这是每个人必须说的:

翻译阶段 1

N1570 C11 草案 5.1.1.2p1.1:

Physical source file multibyte characters are mapped, in an implementation-defined manner, to the source character set (introducing new-line characters for end-of-line indicators) if necessary. Trigraph sequences are replaced by corresponding single-character internal representations.

C++11 2.2p1.1:

Physical source file characters are mapped, in an implementation-defined manner, to the basic source character set (introducing new-line characters for end-of-line indicators) if necessary. The set of physical source file characters accepted is implementation-defined. Trigraph sequences (2.4) are replaced by corresponding single-character internal representations. Any source file character not in the basic source character set (2.3) is replaced by the universal-character-name that designates that character. (An implementation may use any internal encoding, so long as an actual extended character encountered in the source file, and the same extended character expressed in the source file as a universal-character-name (i.e., using the \uXXXX notation), are handled equivalently except where this replacement is reverted in a raw string literal.)

翻译阶段 5

N1570 C11 草案 5.1.1.2p1.5:

Each source character set member and escape sequence in character constants and string literals is converted to the corresponding member of the execution character set; [...]

C++ 2.2p1.5:

Each source character set member in a character literal or a string literal, as well as each escape sequence and universal-character-name in a character literal or a non-raw string literal, is converted to the corresponding member of the execution character set; [...]

(强调差异)

问题

  1. 在 C++11 标准中,很明显,不在基本源字符集中的源文件字符被转换为 UCN,并且它们在同一个地方的处理方式与 UCN 完全相同,唯一的异常(exception)是原始字符串。 C11也是这样吗?当 C11 编译器看到多字节 UTF-8 字符(如 °)时,它是否也在阶段 1 中将其转换为 \u00b0,并将其视为就像 \u00b0 反而出现在那里?

  2. 换句话说,在哪个翻译阶段结束时(如果有的话),以下代码片段是否在 C11 中首次转换为文本等效形式?

    const char* hell° = "hell°";
    

    const char* hell\u00b0 = "hell\u00b0";
    
  3. 如果在 2. 中,答案是“无”,那么尽管文本不同,这两个标识符在哪个翻译阶段首先被理解为指代同一事物?

  4. 在 C11 中,字符/字符串文字中的 UCN 是否也在阶段 5 中转换?如果是这样,为什么要从标准草案中删除它?
  5. 在 C11 和 C++11 中如何处理标识符中的 UCN(相对于已经提到的字符/字符串文字)?他们也在第 5 阶段转换了吗?或者这是实现定义的东西?例如,GCC 是以 UCN 编码形式还是以实际 UTF-8 形式打印出此类标识符?

最佳答案

评论变成了答案

有趣的问题!

C 标准可以保留更多未声明的转换,因为它们是实现定义的(并且 C 没有原始字符串来混淆问题)。

  1. 它在 C 标准中所说的就足够了——除了它让您的问题 1 无法回答。
  2. 我认为第 2 季度必须是“第 5 阶段”,但需要注意的是“ token 流是等效的”。
  3. Q3 严格来说是 N/A,但第 7 阶段可能是答案。
  4. Q4 是"is",之所以这么说是因为它提到了“转义序列”,而 UCN 是转义序列。
  5. Q5 也是“第 5 阶段”。

Can the C++11-mandated processes in Phase 1 and 5 be taken as compliant within the wording of C11 (putting aside raw strings)?

我认为它们实际上是一样的;差异主要来自特定于 C++ 的原始文字问题。一般来说,C 和 C++ 标准尽量不要让事情无缘无故地不同,特别是尝试在两者中预处理器和低级字符解析的工作相同(自从 C99 添加对 C++ 的支持以来,这变得更容易了// 注释,但随着向 C++11 添加原始文字,这显然变得更难了。

有一天,我将不得不更彻底地研究原始文字符号及其含义。

关于c++ - C11 编译。翻译阶段 #1 和 #5。通用字符名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18972735/

有关c++ - C11 编译。翻译阶段 #1 和 #5。通用字符名称的更多相关文章

  1. ruby - i18n Assets 管理/翻译 UI - 2

    我正在使用i18n从头开始​​构建一个多语言网络应用程序,虽然我自己可以处理一大堆yml文件,但我说的语言(非常)有限,最终我想寻求外部帮助帮助。我想知道这里是否有人在使用UI插件/gem(与django上的django-rosetta不同)来处理多个翻译器,其中一些翻译器不愿意或无法处理存储库中的100多个文件,处理语言数据。谢谢&问候,安德拉斯(如果您已经在ruby​​onrails-talk上遇到了这个问题,我们深表歉意) 最佳答案 有一个rails3branchofthetolkgem在github上。您可以通过在Gemfi

  2. ruby-on-rails - 如何优雅地重启 thin + nginx? - 2

    我的瘦服务器配置了nginx,我的ROR应用程序正在它们上运行。在我发布代码更新时运行thinrestart会给我的应用程序带来一些停机时间。我试图弄清楚如何优雅地重启正在运行的Thin实例,但找不到好的解决方案。有没有人能做到这一点? 最佳答案 #Restartjustthethinserverdescribedbythatconfigsudothin-C/etc/thin/mysite.ymlrestartNginx将继续运行并代理请求。如果您将Nginx设置为使用多个上游服务器,例如server{listen80;server

  3. ruby - Sinatra set cache_control to static files in public folder编译错误 - 2

    我不知道为什么,但是当我设置这个设置时它无法编译设置:static_cache_control,[:public,:max_age=>300]这是我得到的syntaxerror,unexpectedtASSOC,expecting']'(SyntaxError)set:static_cache_control,[:public,:max_age=>300]^我只想将“过期”header设置为css、javaascript和图像文件。谢谢。 最佳答案 我猜您使用的是Ruby1.8.7。Sinatra文档中显示的语法似乎是在Ruby1.

  4. ruby - 在 Ruby 中按名称传递函数 - 2

    如何在Ruby中按名称传递函数?(我使用Ruby才几个小时,所以我还在想办法。)nums=[1,2,3,4]#Thisworks,butismoreverbosethanI'dlikenums.eachdo|i|putsiend#InJS,Icouldjustdosomethinglike:#nums.forEach(console.log)#InF#,itwouldbesomethinglike:#List.iternums(printf"%A")#InRuby,IwishIcoulddosomethinglike:nums.eachputs在Ruby中能不能做到类似的简洁?我可以只

  5. ruby - 使用 `+=` 和 `send` 方法 - 2

    如何将send与+=一起使用?a=20;a.send"+=",10undefinedmethod`+='for20:Fixnuma=20;a+=10=>30 最佳答案 恐怕你不能。+=不是方法,而是语法糖。参见http://www.ruby-doc.org/docs/ProgrammingRuby/html/tut_expressions.html它说Incommonwithmanyotherlanguages,Rubyhasasyntacticshortcut:a=a+2maybewrittenasa+=2.你能做的最好的事情是:

  6. ruby - 安装libv8(3.11.8.13)出错,Bundler无法继续 - 2

    运行bundleinstall后出现此错误:Gem::Package::FormatError:nometadatafoundin/Users/jeanosorio/.rvm/gems/ruby-1.9.3-p286/cache/libv8-3.11.8.13-x86_64-darwin-12.gemAnerroroccurredwhileinstallinglibv8(3.11.8.13),andBundlercannotcontinue.Makesurethat`geminstalllibv8-v'3.11.8.13'`succeedsbeforebundling.我试试gemin

  7. 安卓apk修改(Android反编译apk) - 2

    最近因为项目需要,需要将Android手机系统自带的某个系统软件反编译并更改里面某个资源,并重新打包,签名生成新的自定义的apk,下面我来介绍一下我的实现过程。APK修改,分为以下几步:反编译解包,修改,重打包,修改签名等步骤。安卓apk修改准备工作1.系统配置好JavaJDK环境变量2.需要root权限的手机(针对系统自带apk,其他软件免root)3.Auto-Sign签名工具4.apktool工具安卓apk修改开始反编译本文拿Android系统里面的Settings.apk做demo,具体如何将apk获取出来在此就不过多介绍了,直接进入主题:按键win+R输入cmd,打开命令窗口,并将路

  8. ruby-on-rails - 应用程序的名称是否可以作为变量使用? - 2

    当我创建一个Rails应用程序时,控制台:railsnewfoo我的代码可以使用字符串“foo”吗?puts"Yourapp'snameis"+app_name_bar 最佳答案 Rails.application.class将为您提供应用程序的全名(例如YourAppName::Application)。从那里您可以使用Rails.application.class.parent获取模块名称。 关于ruby-on-rails-应用程序的名称是否可以作为变量使用?,我们在StackOve

  9. ruby-on-rails - 如何从过时的 TZInfo 标识符中获取 Rails TimeZone 名称? - 2

    已经有一个问题回答了如何将“America/Los_Angeles”转换为“PacificTime(US&Canada)”。但是我想将“美国/太平洋”和其他过时的时区转换为RailsTimeZone。我无法在图书馆中找到任何可以帮助我完成此任务的东西。 最佳答案 来自RailsActiveSupport::TimeZonedocs:TheversionofTZInfobundledwithActiveSupportonlyincludesthedefinitionsnecessarytosupportthezonesdefinedb

  10. ruby - 如何计算 Liquid 中的变量 +1 - 2

    我对如何计算通过{%assignvar=0%}赋值的变量加一完全感到困惑。这应该是最简单的任务。到目前为止,这是我尝试过的:{%assignamount=0%}{%forvariantinproduct.variants%}{%assignamount=amount+1%}{%endfor%}Amount:{{amount}}结果总是0。也许我忽略了一些明显的东西。也许有更好的方法。我想要存档的只是获取运行的迭代次数。 最佳答案 因为{{incrementamount}}将输出您的变量值并且不会影响{%assign%}定义的变量,我

随机推荐