1. the compiling environment uses VS2008. During the debugging process, it is found that some code of a function is not correctly executed, and breakpoint debugging is performed in this part of code. It is found that the breakpoint is always prompted to be invalid during each debugging operation. The following code indicates that the breakpoint is invalid when a breakpoint is set in the while () {} code block.
[Cpp]
INT32 sendLTEMsg (void * pMsg, INT32 iMsgLen)
{
INT32 t_iLeft = iMsgLen;
INT32 t_iRet = 0;
INT32 t_idx = 0;
If (NULL = pMsg) | (0 = iMsgLen ))
{
Return FALSE;
}
While (t_iLeft> 0)/* Ensure that all data is sent out */
{
T_iRet = send (g_SockClientLTE, & (char *) pMsg) [t_idx]), t_iLeft, 0 );
If (t_iRet = 0)
{
Break;
}
Else if (t_iRet = SOCKET_ERROR)
{
INT32 t_errcode = WSAGetLastError ();
Return FALSE;
}
T_iLeft-= t_iRet;
T_idx + = t_iRet;
}/* End of while */
Return TRUE;
}
2. Under what circumstances will the breakpoint become invalid during running or cannot be set at the specified position?
A) Is there debugging information during compilation?
You need to check the compilation options, debug or release (that is, the optimizationlevel at the time of compilation). debug will have debugging information.
B) Are there any changes to the Code after compilation?
The Code may already be inconsistent with the executable file, resulting in inconsistent breakpoint location with the expected program execution location. For example, the power is stopped at a --, but the program has output hello world.
C) Is this part of code compiled into the target file?
For example, if this part of the code is not compiled due to the impact of Conditional compilation, the breakpoint is not allowed. Then, how can I determine whether the code has been compiled into the target file?
3. Preprocessing command # pragma
# The pragma command is used to set the compiler status or instruct the compiler to complete certain actions. # The pragma command provides a method for each compiler to provide the unique features of the host or operating system while maintaining full compatibility with C and C ++ languages. According to the definition, the compilation instructions are proprietary to machines or operating systems and are different for each compiler. Syntax: # pragma para
# Pragmamessage ("string") displays a message during compilation
# Pragmacode_seg (["section-name" [, "section-class"]) sets the code segment for storing function code in the program.
# Pragmawarning (...) Process warning
# Pragmacomment (...) Put a comment record into an object file or executable file
In the following example, if The pragma preprocessing command is not added to the Code, the system will prompt the 4013 warning message during compilation. pragma can disable prompting a certain warning message and set to display the message during compilation.
4. Run the pre-compiled command # pragma message (…) before and after the problem Code while (t_iLeft> 0 (...), It is found that the while () Statement is compiled before the statement is compiled into the target file. Why?
I personally think it is caused by the greedy method of C compiler lexical analysis (see the description below). We noticed that the while () Statement is followed by a Chinese annotation, followed by a space, and the compilation information appears. During the compilation process of the Code, the compiler considers that the comment after the while () is not complete due to the combination of the Chinese character "Remove" pairs, the code between two comments in the function is regarded as comments! (This may be caused by inconsistent understanding of character encoding by the compiler. The cause is conjecture that this problem does not occur during compilation in the VC6 environment)
Briefly describe what is greedy:
Since learning C language, we have a question: how to explain a ++ B?
If the input stream of the compiler has been decomposed into symbols before a character, the next symbol will include the longest string that may constitute a symbol after the character. There cannot be spaces between symbols.
For example:
[Cpp] int a = 3, B;
Int * p = &;
B = 12/* p/* comment */;
Int a = 3, B;
Int * p = &;
B = 12/* p/* comment */;
What is the value of B?
Or
[Cpp] int * p = NULL;
Int I = sizeof * p;
Int * p = NULL;
Int I = sizeof * p;
Is this representation incorrect?
If you are interested, try it.
From the nevasun Column