标准是否指定了源文件需要如何编译以及额外的预处理步骤是否是非标准的?
这个问题可能有点模糊,但以 Qt 的 moc 步骤为例。它是非标准的还是标准允许的,因为编译器看到的所有内容仍然是纯粹且有效的 C++。另一个例子当然是 config.h 文件,它需要由构建系统生成,就像 moc 文件一样。
我认为标准中没有指定 moc,但也没有禁止。
PS:这个问题的来源源于评论中关于SO的这个小讨论。
The question might be a bit vague, but take as a prime example Qt's moc step. Is it non-standard or allowed by the standard, as everything the compiler sees is still pure and valid C++. Another example would of course be the config.h
file, which needs to be generated by the build system just like the moc files are.
I would think moc is not specified in the Standard, but also not disallowed.
PS: the source of this question stems from this little discussion on SO in the comments.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我这里没有该标准的副本(虽然很久以前阅读了草案的某些部分),但我很确定该标准甚至没有规定源必须以文件形式存在。如果我没记错的话,很久以前(上世纪 90 年代)IBM 的 Visual Age C++ IDE 就试图完全放弃将源代码存储在文件中。
由于 C++ 标准没有提及构建系统(make、jam 或其他),因此编译器(和 C++ 预处理器)之前的所有内容都超出了标准的范围。因此,像 moc 或生成 config.h 这样的东西对于 C++ 标准来说是非标准的,并且也不被禁止。
但还有其他标准。例如,对于 Qt 来说,使用 moc 是调用 C++ 编译器之前预处理文件的“标准”,就像在 Linux 开发中使用 autoconf、GNU make 和其他工具一样。
I don't have a copy of the standard here (long time ago read some portions of the draft though), but I'm quite sure the standard doesn't even dictate sources have to be present as files. If I remember correctly, a long time back (in the 90s) IBM's Visual Age C++ IDE tried to abandon storing sources in files altogether.
Since the C++-standard says nothing about the build system (make, jam, or whatsoever), everything that comes before the compiler (and the C++ preprocessor) is outside the scope of the standard. So, something like moc or generation of config.h is non-standard with regard to the C++-standard, and is not disallowed either.
But there are other standards as well. For example, for Qt using moc is the "standard" for preprocessing files before invoking the C++ compiler, just as in linux development using autoconf, GNU make and other tools is.