Today, I encountered a very strange problem. I have tested a piece of code I have written many times and I have been using it to think that this piece of code is already very stable. But today I updated the database result. This Code turns into a dead code. I really don't believe in my own eyes, however, there is no way to find out, or find the bug, ah, and finally found that it was a variable because of changing the Library's initial value variable, resulting in a pointer being assigned a value without being assigned to the pointer. The following points are summarized:
1. In the switch... case... default statement structure, if there is nothing to do with the default statement, add an asserted.
2. If... else if your thinking is that there must be one of these two situations, you should add one more else.
To avoid your situation today, you can add an asserted in else.
If (pmonitorguiframe-> gsysmod. gmonitorconfig. recsweepspeed = 25)
{
Itemdbcaption [3]. pstrrightcaption = pmonitorguiframe-> getlangstr (ids_dlg_speed_250 );
}
Else if (pmonitorguiframe-> gsysmod. gmonitorconfig. recsweepspeed = 50)
{
Itemdbcaption [3]. pstrrightcaption = pmonitorguiframe-> getlangstr (ids_dlg_speed_500 );
}
Else // avoid pointer pointing to fly
{
Assert (false );
}
Switch (pmonitorguiframe-> gsysmod. gmonitorconfig. recrtmode)
{
Case 8:
Itemdbcaption [4]. pstrrightcaption = pmonitorguiframe-> getlangstr (ids_com_time_8s );
Break;
Case 16:
Itemdbcaption [4]. pstrrightcaption = pmonitorguiframe-> getlangstr (ids_com_time_16s );
Break;
Case 32:
Itemdbcaption [4]. pstrrightcaption = pmonitorguiframe-> getlangstr (ids_com_time_32s );
Break;
Case 120:
Itemdbcaption [4]. pstrrightcaption = pmonitorguiframe-> getlangstr (ids_com_time_continual );
Break;
Default:
Assert (false );
Break;
}