简体   繁体   English

在编译/链接期间,是否会删除#ifdef和#endif中无法访问的代码?

[英]Does unreachable code within #ifdef and #endif get removed during compile/link time?

Does unreachable code within #ifdef and #endif get removed during compile/link time or kept in the executable even though it can not be reached? #ifdef和#endif中无法访问的代码会在编译/链接时被删除,还是被保存在可执行文件中,即使无法访问也是如此?

#ifdef DEBUG
// some debug operations
#endif

Is the debug operation code still kept after compilation without DEBUG flag, and if it is will it affect the performance of release build? 没有DEBUG标志的编译后,调试操作代码是否仍然保留,如果是,它将影响发行版的性能吗?

EDIT: 编辑:

If there were some modules used only in the debug operation, and if it is linked into the program, will this affect the performance? 如果仅在调试操作中使用了某些模块,并且将其链接到程序中,这会影响性能吗?

The preprocessor will completely remove such code - the compiler doesn't even get to see it. 预处理器将完全删除此类代码-编译器甚至看不到它。

You can eg use g++ -E to have a look at what the preprocessor does, and what the compiler gets to see. 例如,您可以使用g++ -E来查看预处理器的功能以及编译器可以看到的内容。

它由预处理器删除(使用外部预处理器时,通常会替换为空行)。

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

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