简体   繁体   English

需要对来自 Go Lang 的声明进行验证

[英]Need validation on a claim from Go Lang

I have been lately looking into GoLang -- coming from C++ background-- I am reading a paper which allegedly explains the reasoning behind making Golang, here is its link: https://talks.golang.org/2012/splash.article我最近一直在研究 GoLang——来自 C++ 背景——我正在阅读一篇论文,据称解释了制作 Golang 背后的原因,这里是它的链接: https://talks.golang.org/2012/splash.article

One of the claims being is, handling Dependencies (Package) in C and C++ is pain and takes on a #ifndef guard instance to state索赔之一是,处理 C 和 C++ 中的依赖项(包)是痛苦的,并且对 state 采取#ifndef保护实例

The intent is that the C preprocessor reads in the file but disregards the contents on the second and subsequent readings of the file...目的是 C 预处理器读取文件,但忽略文件的第二次和后续读取的内容......

I referred a GCC page for the same, https://gcc.gnu.org/onlinedocs/cppinternals/Guard-Macros.html .我参考了 GCC 页面, https://gcc.gnu.org/onlinedocs/cppinternals/Guard-Macros.ZFC35FDC70D5FC69D2698Z83A822C7A53.E

so that if the header file appears in a subsequent #include directive and FOO is defined, then it is ignored and it doesn't preprocess or even re-open the file a second time因此,如果 header 文件出现在随后的 #include 指令中并且定义了 FOO ,则它会被忽略,并且不会预处理甚至第二次重新打开文件

Go: "Reads in and disregard" vs GCC: it doesn't preprocess or even re-open the file a second time. Go:“读取并忽略”与 GCC:它不会预处理甚至第二次重新打开文件。

Doesn't contradict?不矛盾吗?

your thoughts are appreciated.感谢您的想法。 Thanks for Reading my question.感谢您阅读我的问题。

The first passage is talking about a generic compiler, which, conceptually speaking, should read the contents of the file and disregard the contents (because they are #ifdef d out).第一段是讨论通用编译器,从概念上讲,它应该读取文件的内容并忽略内容(因为它们是#ifdef d out)。 That is, roughly, what the C standard specifies a compiler should do.也就是说,粗略地说,C 标准指定编译器应该做什么。

But practically everything in the C standard is under the "as if" rule - a compiler does not actually have to be implemented in the way suggested in the standard, so long as the end result it produces is exactly the same in every case.但实际上 C 标准中的所有内容都在“好像”规则之下——编译器实际上不必按照标准中建议的方式实现,只要它产生的最终结果在每种情况下都完全相同。 As such, GCC's particular implementation adds an optimization where, in cases where it can tell with certainty that the contents of the file would be disregarded, it doesn't actually read it.因此,GCC 的特定实现添加了一个优化,在它可以确定文件的内容将被忽略的情况下,它实际上并没有读取它。 This is perfectly fine because it still behaves as if it has read the file but disregarded it.这很好,因为它仍然表现得好像它已经读取了文件但忽略了它。

Note that other compilers do not necessarily do the same.请注意,其他编译器不一定会这样做。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM