Code Snippets/Boost2012. 2. 23. 11:50

C++0X를 사용 못할 상황이 생겼다.
lambda 사용을 제거해야 하는데 매번 functor class를 만들어 주는 것도 만만치 않다.
bind를 잘 사용하면 될 것 같아서 해 봤는데,
lambda 사용 버전과 미사용 버전은 그 편의성과 직관성에서 비교가 되지 않는 것 같다.
그래도, 간단한 lambda에 대해서는 fuctor class를 만드는 것보다는 나을 것 같아서 정리해 본다.

'Code Snippets > Boost' 카테고리의 다른 글

함수 호출 연기 & 함수 타입 캐스팅  (0) 2010.09.17
Nested Bind  (0) 2010.09.09
Generalized Function Pointers  (0) 2010.09.06
boost::bind 활용  (0) 2010.09.03
boost 관련 유용한 링크 모음  (0) 2010.08.20
Posted by codevania
Debug2011. 9. 3. 16:43

자주 나오는 매직 발류들에 대해서 정리.
자세한 정보는 여기 참조.



* 0xCCCCCCCC : Allocated on stack, but not initialized
* 0xCDCDCDCD : Allocated in heap, but not initialized (Debug)
* 0xBAADF00D : Allocated in heap, but not initialized (Release)
* 0xDDDDDDDD : Released heap memory.
* 0xFDFDFDFD : automatically placed at boundary of heap memory. Should never be overwritten.




[ StackOverflow 펌 ]
* 0xABABABAB : Used by Microsoft's HeapAlloc() to mark "no man's land" guard bytes
               after allocated heap memory

* 0xABADCAFE : A startup to this value to initialize all free memory to catch errant pointers
* 0xBAADF00D : Used by Microsoft's LocalAlloc(LMEM_FIXED) to mark uninitialised allocated
               heap memory

* 0xBADCAB1E : Error Code returned to the Microsoft eVC debugger when connection is severed
               to the debugger

* 0xBEEFCACE : Used by Microsoft .NET as a magic number in resource files
* 0xCCCCCCCC : Used by Microsoft's C++ debugging runtime library to mark uninitialised
               stack memory

* 0xCDCDCDCD : Used by Microsoft's C++ debugging runtime library to mark uninitialised
               heap memory

* 0xDEADDEAD : A Microsoft Windows STOP Error code used when the user manually initiates
               the crash.

* 0xFDFDFDFD : Used by Microsoft's C++ debugging heap to mark "no man's land" guard bytes before
               and after allocated heap memory

* 0xFEEEFEEE : Used by Microsoft's HeapFree() to mark freed heap memory

'Debug' 카테고리의 다른 글

Debug variables about STL  (0) 2011.08.18
재컴파일 없이 프로그램 실행 로직 제어하기  (0) 2010.08.20
Posted by codevania
Debug2011. 8. 18. 00:00

Debug할 때 "Condition..." 또는 "When Hit..."에서 string::empty() 같은 함수들의 return 값은 기대한 결과를 반환하지 않는다.
그러나 변수의 값은 결과를 기대할 것도 없이 그냥 그 값이다.
그래서 "Condition..."에서 다음과 같이 함수가 아닌 변수로 조건을 걸면 문자열이 0인 경우 break가 잡힌다.
>> strWhat._Mysize == 0

이왕 정리하는 김에 유용한 것들을 기록해 본다.
(MS STL 기준. Debug mode)



string
_Bx        : 실제 인스턴스
_Bx._Buf   : 문자들이 16개 이하일 때의 저장소 (\0 포함)
_Bx->_Ptr  : 문자들이 16개 초과일 때의 포인터
_Mysize    : 문자열 길이
max_size() : 0xffffffff. 4294967295개를 넘을 수 없다.
_BUF_SIZE <= _Myres : true -> _Buf  /  false -> *_Ptr

list
_Myhead    : Head node의 포인터
_Mysize    : list의 element 개수
max_size() : 0x3fffffff. 1073741823개를 넘을 수 없다.

vector
_Myfirst   : 배열의 시작 포인터
_Mylast    : element sequence의 끝 포인터. size와 관련.
_Myend     : 배열의 끝 포인터. capacity와 관련.
_Mylast - _Myfirst : 배열의 크기. (_Mysize가 없다)


map / set
_Myhead    : 헤드 노드 포인터
_Mysize    : 크기


Note.
리스트의 erase함수는 list의 장점을 좀 못 살리고 있다.
element들을 delete하기 위해 while문을 돌면서 하나하나 삭제 한다.
음... 따로 방법이 없나? -_-;;
덕분에 Size를 바로 구할 수 있는 점은 좋지만... 누가 size를 자주 구할 목적으로 list를 사용할까?

'Debug' 카테고리의 다른 글

Magic debug values  (0) 2011.09.03
재컴파일 없이 프로그램 실행 로직 제어하기  (0) 2010.08.20
Posted by codevania
Troubleshooting2011. 8. 3. 00:17

다음과 같은 상황을 의심해 보자.
숫자가 낮을 수록 발생 확률이 높을 것으로 예상한다.


1. map/set의 iterator를 그 map/set의 복사본의 begin()/end()와 비교한 것은 아닌가?
2. const iterator 와 iterator를 비교하고 있나?
3. 공유자원인 map/set의 스레드간 동기화가 잘 되고 있나?
Posted by codevania
Graphics2011. 7. 11. 17:12

쉐이더가 아닌 곳에서 이 방법을 쓰게 되었다. -_-ㅋ
(손실 압축)

http://www.gpwiki.org/index.php/MathGem:Color_Operations


>>
Original
   5, 4, -3

[-1:1] <- Normalieze
   0.707107, 0.565685, -0.424264

[0:1] <- Prepare to encode  { x` = (x+1)/2 }
   0.853553, 0.782843, 0.287868

Compressed Vec3       { x` = x * 255 }
   217, 199, 73

Compressed 4 BYTE
   ffd9c749


... Now restore value ...


DWORD -> 4 BYTE
   217, 199, 73

[0:1] <- Prepare to decode
   0.85098, 0.780392, 0.286275

[-1:1] <- Normalize  { x = (x`*2)-1 }
   0.701961, 0.560784, -0.427451

'Graphics' 카테고리의 다른 글

Normal Transform  (0) 2010.09.07
Posted by codevania
Tip2011. 3. 31. 03:25

SEH

Structured Exception Handling

자세한 설명은 아래 링크들을 참조.
여기서는 Windows Exception이 발생했을 때...
등록된 콜백함수의 파라미터를 이용해서 예외가 발생한 지점의 파일과 라인을 출력하는 예제를 보여준다.
말 그대로 그냥 예제... -_-;

예제


출력
[ main - 1 ]
[ TranslateSEHtoCE - 1 ]
Symbol name: main
FileName:d:\programming\mytest2010\mytest2010\mytest2010.cpp (Line:125)
[ main - 4 Access Violationn ]


링크
* serious-code: SEH
* 엘키님 블로그: 여기 예제 코드의 전신
* MSDN: Initializing the Symbol Handler
* MSDN: Retrieving Symbol Information by Address

'Tip' 카테고리의 다른 글

Rvalue References and Perfect Forwarding  (0) 2011.01.12
Set a Thread Name in Native Code  (0) 2010.12.03
Remote Debugging  (0) 2010.11.23
IsNaN  (0) 2010.11.02
Failed to create .NET Frameworks PropertyGrid component  (0) 2010.08.20
Posted by codevania
Troubleshooting2011. 3. 15. 15:41


VS2010 SP1이 나와서 깔았더니 왠 -_-;;;
아래 링크의 내용을 참조하자~

Tim Odell's Blog
Mike Kaufman's reply


Odell의 블로그 내용은 너무 말이 많다ㅋ
Mike가 시키는 데로 하면된다.

... 하지만 왜 언인스톨을 해야하지 -_-;;;
MS 밉다 -_ㅜ
Posted by codevania
Tip2011. 1. 12. 12:29


자세한 건...
http://www.justsoftwaresolutions.co.uk/cplusplus/rvalue_references_and_perfect_forwarding.html

링크 내용중 일부

X x;
X& lref = x;
          // bind lvalue reference to object: fine
X&& rref = x;       // bind rvalue reference to object: fine too.
X&& rref2 = lref;  // bind rvalue reference to lvalue ref: fine
X& lref2 = X();     // bind lvalue reference to temporary (rvalue): error
X&& rref3 = X();  // bind rvalue reference to temporary (rvalue): fine, extends lifetime of temporary

'Tip' 카테고리의 다른 글

SEH  (0) 2011.03.31
Set a Thread Name in Native Code  (0) 2010.12.03
Remote Debugging  (0) 2010.11.23
IsNaN  (0) 2010.11.02
Failed to create .NET Frameworks PropertyGrid component  (0) 2010.08.20
Posted by codevania
Troubleshooting2011. 1. 11. 12:26
비쥬얼 스튜디오 실행시, IDE는 뜨지도 않고 에러 다이얼로그 박스만 뜨는 경우가 생겼다.
아래와 같은 메세지의 에러 다이얼로그 박스가 뜨는데...

[ KOR ]
- devenv.exe - 시작 지점 없음
- 프로시저 시작 지점 wmemcpy_s을(를) DLL MSVCR100.dll에서 찾을 수 없습니다.

[ ENG ]
- devenv.exe - No entry point
- The procedure entry point Wmemcpy_s could not be located in msvcr100.dll

발생 원인은 다음과 같은 것들이 있었다.
- DVD설치가 아닌 '제어판/프로그램/프로그램 가져오기'에서 설치 -> (Install SP1) -> execute 'devenv'
- Install Ultimate -> Uninstall Ultimate -> Install Premium(or Professional) -> (Install SP1) -> execute 'devenv'

해결방법은...
- 괜히 다른 것들 삭제할 필요없다. 프로그램 제거에서 'VS 2010'만 삭제 후 -> 리붓 -> VS 2010 재설치
- 재설치 해도 안 될 때, C:/windows/system32/MSVCR100.dll을 $(VSInstallDir)/Common7/IDE에 복사

'Troubleshooting' 카테고리의 다른 글

map/set iterators incompatible  (0) 2011.08.03
Resolving BootstrapPackage Load Error: Visual Studio 2010  (0) 2011.03.15
Conversion from VS2005 to VS2010  (0) 2010.12.14
Break when an exception is  (0) 2010.12.03
마일스 사운드 버그  (3) 2010.11.17
Posted by codevania
Troubleshooting2010. 12. 14. 12:24
발생했던 문제점들에 대한 해결 방법들을 공유합니다.

- boost
    - 1_44_0으로 갈아탐

- 변환시 vcproj 패스 설정 오류
    - Property Manager > Common Properties > User Macro의 경로중 하나가 잘못 컨버팅되서 재조정.
    - Ex) D:XXX/YYY/ZZZ/ZZZ 처럼... 2010으로의 자동 변환 후에 ZZZ가 두번 들어가 있었음.

- vs2010 error C2039: 'back_insert_iterator'
    - 인클루드 코드 삽입: #include <iterator>
    - PCH에 넣어도 되고, 에러가 난 파일의 헤더에 넣어도 되고~
   
- warning MSB8012: TargetPath does not match the Library's OutputFile property value
    - 이름을 맞춰줌
        - Property Page > Configuration Properties > General - Target Name과 Target Extension
        - Property Page > Configuration Properties > Librarian > General - Output File
    - http://blog.kalmbach-software.de/2010/04/27/converting-vc-projects-to-vc2010-warning-msb8012/
   
- Constructor for class 'Foo' is declared 'explicit'
    - 참조나 포인터가 아닌 객체로 함수의 인자가 되는 경우, 복사 생성이 암시적으로 발생하는데...
    - 복사생성자가 explicit으로 되어있을 경우, 2010에서는 error처리를 해준다. 땡큐!
    - 2010전에는 이것을 error로 처리 안 해줘서 그냥 넘어갔었고, 그래서 잘못된 것인지도 몰랐던거임. -_-;
   
- queue
    - queItems.c.clear()를 사용하고 있는 코드 발견 -_-;;;
    - Queue에 swap이 없긴 하지만, 저런식의 사용은 안 좋다고 본다.
    - 다른 방식으로 clear 할 수 있다
        - queItems.swap( queue<int>() ); 
        - std::swap( m_InfoQue, queue<int>() );

- warning MSB4011:
    "D:\XXX\XXX-Props\KUF2_PhysicalPath.props" cannot be imported again.
    It was already imported at
    "D:\XXX\XXX-Props\KUF2_Paths.props (4,5)".
    This is most likely a build authoring error. This subsequent import will be ignored.
    - Property Manger를 열어서 경고가 뜬 프로젝트의 Property Sheet 참조를 확인 해본다.
    - 이 경우는 임포트가 두 번 되어서 무시하겠다는 건데, 삭제 해주니 해결되었음.

- error LNK2038: mismatch detected for ‘_ITERATOR_DEBUG_LEVEL’: value ‘0′ doesn’t match value ‘2′
    - http://stackoverflow.com/questions/4130044/what-does-iterator-debug-level-1-mean
         _ITERATOR_DEBUG_LEVEL = 0 (in release mode)
        _ITERATOR_DEBUG_LEVEL = 1 (in release mode if _SECURE_SCL is defined)
        _ITERATOR_DEBUG_LEVEL = 2 (in debug mode)        
    - http://blogs.msdn.com/b/vcblog/archive/2009/06/23/stl-performance.aspx
   
- #error _ITERATOR_DEBUG_LEVEL == 2 must imply _HAS_ITERATOR_DEBUGGING == 1 .
    - 코드가 아닌 곳에 디파인 되어 있을 수 있는데, 다음 2가지 경우가 있음.
      텍스트 검색으로 _HAS_ITERATOR_DEBUGGING을 찾아서 수동으로 변경.
        - 프로젝트 파일에 _HAS_ITERATOR_DEBUGGING이 0으로 디파인되어 있는 경우.
          Property Page > Configuration Properties > C/C++ > Preprocessor - Preprocessor Definitions
        - *.props 파일에 디파인되어 있을 수 있음.
        - Runtime Library가 일치하지 않는 프로젝트가 존재할 수 있음.
   
- XXX.lib(xxx.obj) : error LNK2019: unresolved external symbol
    - Menu > Project > Project Dependencies - 여기서 체크박스만 해주면 안되네;;
    - Menu > Project > Properties > Common Properties - Framework and References에서 Add New Reference... 눌러서 추가해 줘야함.
   
- 외부 라이브러리 2010으로 리빌드하면서 MSB8012 경고 잡아주기
    - yaml
    - loki
    - squirrel
    - sqplus

- libcpmtd.lib(xdebug.obj) : warning LNK4098: defaultlib 'libcmt.lib' conflicts with use of other libs; use /NODEFAULTLIB:library
    - Ignore Specific Default Libraries에 libcmt.lib 추가
    - 지금까진 libcmt를 무시하라는 에러메세지가 뜬다고 해도 다른 방법으로 해결했었는데, 이번엔 잘 모르겠음;; 그냥 추가;;
    - Properties > Configuration Properties > Linker > Input - Ignore Specific Default Libraries
   
- warning C4717: 'SquirrelObject::Set<SquirrelObject>' : recursive on all control paths, function will cause runtime stack overflow   
    - 템플릿 매치 우선순위에 대한 문제였습니다.        
        - http://stackoverflow.com/questions/4427683/template-functions-priority-is-diferent-between-vs2005-and-vs2010
        - VS2005와 VS2010에서의 결과가 다릅니다.
        - Foo(const Foo&); ? Foo(Foo&) 로 변경해서 해결
    - 어쨌든 좀 혼란스러운 점이 있는데, 이를 C++ committee에서 곧 결정할 것이고, VS2010에서 이를 바로 반영한다고 합니다.

- :VCEnd" exited with code 1.
    - Exit code 1 indicates ~~~ path is not correct.
    - Post-Build Event에서 copy 명령이 있는데, 거기서 문제 발생.
    - 1이라는 말은 경로가 잘 못되어 있다는 말임. 경로 바꿔주고 해결.
    - 위에 기술된 warning MSB8012을 해결하기 위해서 경로들을 바꾸다 보니 발생했음.   

- LINK : fatal error C1047: The object or library file 'D:\XXX\YYY\ZZZ.lib' was created with an older compiler than other objects; rebuild old objects and libraries
    - ZZZ.lib 또는 ZZZ.lib가 쓰는 xxx.lib가 2010에서 빌드된 lib이 아니란 말.
    - 해당 라이브러리 빌드하면 해결됨.


[ 참조 ]

- Visual Studio 2010 C++ Project Upgrade Guide
    - http://blogs.msdn.com/b/vcblog/archive/2010/03/02/visual-studio-2010-c-project-upgrade-guide.aspx

- VS2010의 새로운 기능
    - 한: http://msdn.microsoft.com/ko-kr/library/dd465215.aspx
    - 영: http://msdn.microsoft.com/en-us/library/dd465215.aspx

- auto 사용
    - 추가 옵션 창에서 설정해 줘야함
    - Menu > Project > Properties > Configuration Properties > C/C++ > Command Line
        - Additional Options에서 다음을 입력 ( /Zc:auto )
    - ...하지만 설정 안 해줘도 됨 -_-; /Zc:auto- 하기 위해서는 설정해야할 것 같음.
    - http://msdn.microsoft.com/en-us/library/dd293615.aspx

- XP를 지원하기 위해 _WIN32_WINNT는 0X0501으로 정의
    - http://msdn.microsoft.com/en-us/library/aa383745(v=vs.85).aspx

- Tools > Options > Projects and Solutions > VC++ Project Settings - Build Timinig의 정보가 좀 더 자세하게 변경되었음
Posted by codevania