아래는 실제 필드에서 발생한 버그이다. 소스코드를 아무리 봐도, 컴파일러가 뱉어내는 에러를 아무리 되짚어 봐도 문제의 원인은 나오지 않는다. 덕분에 잡는데 굉장히 힘들었었다.
컴파일러 : Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 12.00.8804 for 80x86
case #1
1181 : if( logAddr.nPort > 0 ) m_pLogClient->Init( logAddr );
1182 :
1183 : DWORD dwLoadingTime;
1184 : dwLoadingTime = timeGetTime();
---------------------------------------------------------------------------
Compiling...
SlServerZone.cpp
C:ProjectUpdateSlOnlineServer_UpdateServerObjectsSlServerZone.cpp(1184) : error C2065: 'dwLoadingTime' : undeclared identifier
Error executing cl.exe.
case #2
1180 : if( logAddr.nPort > 0 ) m_pLogClient->Init( logAddr );
1181 :
1182 : DWORD dwLoadingTime;
1183 : DWORD dwLoadingTime;
1184 : dwLoadingTime = timeGetTime();
---------------------------------------------------------------------------
Compiling...
SlServerZone.cpp
C:ProjectUpdateSlOnlineServer_UpdateServerObjectsSlServerZone.cpp(1182) : warning C4101: 'dwLoadingTime' : unreferenced local variable
SlServerZone.obj - 0 error(s), 1 warning(s)
case #3
1181: if( logAddr.nPort > 0 ) {
1182: m_pLogClient->Init( logAddr );
1183: }
1184:
1185: DWORD dwLoadingTime;
1186: dwLoadingTime = timeGetTime();
---------------------------------------------------------------------------
Compiling...
SlServerZone.cpp
SlServerZone.obj - 0 error(s), 0 warning(s)
case #4
1181: DWORD dwLoadingTime;
1182:
1183: if( logAddr.nPort > 0 ) m_pLogClient->Init( logAddr );
1184: dwLoadingTime = timeGetTime();
---------------------------------------------------------------------------
Compiling...
SlServerZone.cpp
SlServerZone.obj - 0 error(s), 0 warning(s)
500 여개의 헤더 파일중 어딘가에 이런 매크로가 있었다. 누군가 로그 출력을 잠시 disable 하기위해 매크로를 사용한 것이다.
#define m_pLogClient /##/
매크로의 가장 큰 문제는 "컴파일러가 코드를 읽기 전에 텍스트를 바꿔 버린다는 것" 이라고 스트라우스럽 아저씨는 지적한바 있다. 위의 예에서는 해당 코드와 에러 메세지는 컴파일 에러를 잡는데 전혀 도움이 되지 않는다.