开发者

Does the Standard specify how a source file needs to be compiled and would an extra preprocessing step be non-Standard?

开发者 https://www.devze.com 2023-02-15 08:43 出处:网络
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 examp

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 questi开发者_运维技巧on stems from this little discussion on SO in the comments.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消