开发者

is Qt a conforming C++ implementation?

Does the C++ standard implicitly or explicitly allow such language extensions (o开发者_运维问答r use whatever other term you like) as MOC is?

That is, can we technically call Qt (including MOC) a conforming C++ implementation?


The standard doesn't tell you that you shouldn't preprocess your files before compiling them, and that is what moc does, so that is perfectly legal. And Qt is a library for C++, not an implementation of the language.


MOC is a code generator, not a language extension. All code moc generates you could also write by hand (it would be time-consuming, mind-numbing and error-prone though). Qt uses a few macros such as Q_OBJECT, Q_SIGNALS, Q_SLOTS etc. for the declarations and to give hints to moc. This is perfectly "legal" usage of the preprocessor. The only thing you might consider non-standard is the extra step running the moc to generate the extra code when building the project. That's a matter of the build system though (and code generation is not that unusual, see parsers, IPC interfaces etc.) and outside the scope of C++ as such.


MOC is technically a preprocessor, and therefore irrelevant to the question of C++ compliance.


The input to MOC is not conforming C++ - MOC accepts keywords such as slots and signals. But the output from MOC is conforming C++.

Edited to reply to Frank Osterfeld's coment (I couldn't reply in a comment, I need the formatting):

slots and signals are keywords to the MOC preprocessor. If Q_MOC_RUN is defined (which it is when MOC runs), then qobjectdefs.h has:

#define slots slots
#define signals signals

which leaves them unsubstituted.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜