简体   繁体   English

#ifndef _Python_CALL 在 C++ 代码中是什么意思?

[英]What does #ifndef _Python_CALL mean in a C++ code?

I am debugging a C++ code which contains something related to Python.我正在调试包含与 Python 相关的内容的 C++ 代码。 In a function:在 function 中:

void normalize(string &text) {

...

#ifdef _Python_CALL
    newContentStr = contentStr;
#endif
#ifndef _Python_CALL
   ...
   ...
#endif

return 0;

}

I am using GDB to keep track of the code logic, and I found that after it reaches the line:我正在使用 GDB 来跟踪代码逻辑,我发现到达该行后:

newContentStr = contentStr;

It then directly jumps to the last line in the function:然后直接跳转到function的最后一行:

return 0;

Why is the code between the following is skipped?为什么下面之间的代码被跳过了?

#ifndef _Python_CALL
       ...
       ...
    #endif

Also note that the first is "#ifdef" and the 2nd is "#ifndef".另请注意,第一个是“#ifdef”,第二个是“#ifndef”。 Does that make the skip?这会跳过吗?

#ifndef is the opposite of #ifdef . #ifndef#ifdef相反。

In your case, #ifdef is true, so it jump to return 0 directly and omit #ifndef block.在你的情况下, #ifdef是真的,所以它跳转到直接return 0并省略#ifndef块。

see this official doc看这个官方文档

Judging from the code fragment you've shown, _Python_CALL is a macro name, possibly defined somewhere via #define _Python_CALL (or maybe by some other means, such as using a command line argument to the C++ compiler during compilation).从您显示的代码片段来看, _Python_CALL是一个宏名称,可能通过#define _Python_CALL在某处定义(或者可能通过其他方式,例如在编译期间使用 C++ 编译器的命令行参数)。

Then, line #ifdef _Python_CALL means that everything that follows it until the line #endif will be compiled (and thus executed in the compiled program) if and only if the macro name _Python_CALL is defined (the #ifdef means "if defined").然后, #ifdef _Python_CALL行意味着当且仅当宏名称_Python_CALL被定义( #ifdef表示“如果定义”)时,在它之后的所有内容直到#endif行将被编译(并因此在编译的程序中执行)。 Since you claim that the line newContentStr = contentStr;由于您声称该行newContentStr = contentStr; was executed, we can assume that the macro name _Python_CALL was indeed defined during compilation.执行后,我们可以假设宏名_Python_CALL确实是在编译期间定义的。

Now, the line #ifndef _Python_CALL means that everything that follows it until the line #endif will be compiled (and executed) if and only if the macro name _Python_CALL is NOT defined.现在, #ifndef _Python_CALL行意味着当且仅当宏名称_Python_CALL未定义时,直到#endif行之前的所有内容都将被编译(并执行)。 (Note the n in #ifndef , it means "if not defined"). (注意#ifndef中的n ,它的意思是“如果未定义”)。 But, as we already know (from the conclusion we made in the previous paragraph), this is not the case, because _Python_CALL is indeed defined.但是,正如我们已经知道的(从我们在上一段中得出的结论),情况并非如此,因为确实定义了_Python_CALL Thus, this block will not be compiled/executed.因此,该块将不会被编译/执行。

On Cppreference, you can read more about C++ preprocessor , especially about #define and #ifdef / #ifndef directives, to gain deeper understanding.在 Cppreference 上,您可以阅读有关 C++预处理器的更多信息,尤其是有关#define#ifdef / #ifndef指令的信息,以获得更深入的了解。

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

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