stack size 변경

다음과 같은 코드를 실행하면

아래와 같은 오류를 만나게 된다.
스택에 생성되는 로컬변수들의 크기가 스택사이즈를 초과하였기 때문에 발생하는 에러이다.

해결방법은 소스를 수정하여 스택사이즈를 넘지 않게 수정하는 방법이 있고 다른 방법으로는 프로그램에서 사용하는 스택 사이즈를 늘려 주는 방법이 있다

프로그램에서 사용하는 스택사이즈를 늘리려면
해당 프로젝트의 Property Page - Linker - System의 Stack Reserve Size를 수정해 주면 된다.
아래 설명에 있듯이 기본적으로 1MB를 사용하게 된다.
(CPU 아키텍쳐에 따라 다르다고 한다. 자세한 내용은 http://msdn.microsoft.com/en-us/library/8cxs58a6(v=VS.100).aspx 참고)

2번째 이미지의 Call Stack의 _chkstk()를 기억해 놓자(스택관련된 오류에 단골로 등장하니까.. 그리고 아래 페이지를 꼭 읽어두자)
http://www.codeguru.com/cpp/v-s/debug/memoryissues/article.php/c19241/Adventures-with-chkstk.htm


리눅스에서는 ulimit -a 로 현재 스택사이즈를 파악할 수 있으며, ulimit -s 옵션으로 스택사이즈 수정이 가능하다.
코드에서는 core파일 남길때와 유사하게 system call getrlimit/setrlimit() 함수를 RLIMIT_STACK 옵션으로 호출하여 수정하면 된다.

tortoise svn merge 기능 사용하기

tortoise svn(이하 svn)을 가지고 trunk 와 branch 간에 merge 하는 방법을 소개한다.

svn에서 머지하는 방법은 여러방법이 있는데(merge 관련 팝업메뉴가 여러군데서 뜨기 때문에)
크게 원본인 trunk 디렉토리에서 시작하는 방법(merge to)과 branch 디렉토리에서 시작하는 방법(merge)가 있을 것 같은데,
당연히 결과물도 같고 중간에 거치는 내용도 같기 때문에 취향대로 골라서 사용하면 되겠다.

상황은 trunk에서 branch로 merge하는 상황을 가정한다.
(생각해보니 일반적인 상황이라면 branch에서 trunk로 merge 하는게 많을 듯 한데...)

#include <stdio.h>

int main()
{
         printf("Hello world!\n");

         printf("for delete\n");

         return 0;
}




1. trunk 디렉토리(수정된 원본)에서 시작하는 방법

(1) trunk 루트에서 show log를 선택한다.

(2) 머지하고자 하는 리비전을 확인 후 선택(여러개도 가능)한 후에 merge revision to를 선택한다.
(3) merge 할 대상 디렉토리를 선택한다.
(4) 문제(conflict)가 없다면 merge 가 완료된다.
(5) branch 디렉토리에 가보면 merge된 내용이 적용된 파일들은 modify  상태가 되어 있다. 확인 후 커밋하면 완료된다.



2. branch 디렉토리(수정할 대상)에서 시작하는 방법

(1) trunk에서 가져올 수정된 내용을 확인한다.
(2) branch 루트에서 merge 메뉴를 선택한다.
(3) merge 방식을 선택한다.(여기서는 특정 리비전을 가져오기 위한것으로 merge a range of revisions를 선택함)
(4) merge 해 올 소스 repository 와 revision 을 선택할 수 있는 창이 열린다.
(5) URL to merge from 은 trunk 를 선택
(6) 가져올 revision 선택
(7) 가져올 repository와 revision 을 확인한다.
(8) merge 실행시 세부 옵션을 선택한다. 여기까지 마쳤으면 Test merge 버튼을 눌러 merge 테스트를 해본다.
(9) Merge Test 결과를 확인 후 Merge 버튼을 누르면 merge가 완료된다. branch에 가서 확인 후 커밋한다.

3. merge 과정 중 conflict가 발생했을 경우

(1) trunk 관련소스
(2) branch 관련소스
(3) 위와같이 서로 다른 repository에서 같은 라인이 다르게 수정되면 merge시에 당연히 conflict가 발생하게 된다.
이 경우 merge를 실행하면, 아래와 같이 conflict를 resolve 할 수 있도록 선택창이 뜬다.
내용은 Choose item, Resolve conflict, Leave conflicted 이렇게 3가지다.

Choose item은 merge원본과 대상중에 하나의 것으로 선택하여 conflict를 해결하는 방법이고(local이면 merge할 대상파일 내용으로, repo면 원본이겠죠?)

Resolve conflict내용중 Edit conflict를 누르면 충돌나는 부분을 해결할 수 있게 diff 에디터가 실행되어, resolve를 할 수있게 하고

Leave conflicted 버튼들을 선택하면 충돌난 상태 그대로 놔두게 된다.(일반적인 conflict 상황처럼 해결하면 된다)


(4) 선호하는 방법에 따라 해결하면 된다.(여기서는 Resolve later를 실행해서 Conflicted 상태로 merge 되게 만들었다)
일반적인 Conflict 상황과 동일하므로 해결하고 Commit하면 완료된다.






ipch 디렉토리와 .sdf 파일 위치 바꾸기

비주얼 스튜디오 2010을 사용하면 sdf 파일과 ipch라는 디렉토리가 생기게 되는데 기존의 .ncb 파일을 대치하는 인텔리센스와 관련된 파일이다.

When you open the solution for the first time in Visual C++ Express the environment will parse the source files and generate the code browser database, the .sdf file, and a folder called ipch which contains the IntelliSense pre-compiled header files that are used to provide IntelliSense information as the developer types code. This means that if you intend to distribute the solution, the absolute minimum collection of files that you should include are the code and resource files, the .sln file, and the project files .vcxproj and .vcxproj.filters, all the other files will be generated by Visual C++ if they do not exist.
http://msdn.microsoft.com/en-us/library/ff795784.aspx

인텔리센스를 위해 각 솔루션 위치마다 ipch 디렉토리와 .sdf 파일이 생기게 되는데, 맘에 들지 않는다면 이 파일들이 위치할 디렉토리를 정해줄 수가 있다.
http://wronso.com/blog/553/why-does-visual-studio-2010-create-ipch-folder-and-sdf-file.html

“Tools > Options”, choose “Text Editor > C/C++ > Advanced”, scroll down until “Fallback Location” appears. Make “Always use Fallback Location” and “Do Not Warn if Fallback Location” to be “True”, and choose a “Fallback Location” you like.


이렇게 지정해주면 인텔리센스 관련된 파일은 지정해둔 fallback 디렉토리에 생성되게 된다.

su, sudo

su

다른 사용자로 전환한다.

su - [계정] 옵션으로 실행하면 해당 계정으로 쉘을 실행한다.
- 옵션을 주지 않으면 기존유저의 환경변수를 그대로 사용한다.(새로운 쉘이 아니다)
전환할 유저 계정명을 주지 않으면 기본으로 root로 간주하며, 전환시에는 전환할 유저의 패스워드를 묻게된다.(root 유저가 전환할 경우 제외)


sudo

root 혹은 다른 유저로 명령을 실행한다.

/etc/sudoers 파일을 수정하여 설정할 수 있다.(혹은 visudo 명령으로)

#vi /etc/sudoers
root ALL=(ALL) ALL
nongsa ALL=(root) /usr/sbin/useradd, (code) /sbin/mount.cifs

위와같이 "계정명 호스트=(실행권한계정) 명령어" 형태로 등록해 주면 된다. 명령어는 ,로 구별하여 적어준다.
sudo명령을 사용하면 패스워드를 묻는데, 자신의 패스워드를 입력한다.
-u [계정] 옵션으로 특정유저로 명령을 실행할 수 있다.


Preprocessor Definitions

디버깅 속도 향상 및 경고제거를 위해 몇몇 플래그를 설정할 수 있다.

_SCL_SECURE_NO_WARNINGS
Calling any one of the potentially unsafe methods in the Standard C++ Library will result in Compiler Warning (level 3) C4996. To disable this warning, define the macro _SCL_SECURE_NO_WARNINGS in your code
http://msdn.microsoft.com/ko-kr/library/aa985974(v=vs.90).aspx

_CRT_SECURE_NO_WARNINGS
There are several ways to eliminate deprecation warnings for the older, less secure functions. The simplest is simply to define _CRT_SECURE_NO_DEPRECATE or use the warning pragma. Either will disable deprecation warnings, but of course the security issues that caused the warnings still exist. It is far better to leave deprecation warnings enabled and take advantage of the new CRT security features.
http://msdn.microsoft.com/ko-kr/library/8ef0s5kh(v=VS.80).aspx

_SECURE_SCL = 0
Defines whether Checked Iterators are enabled. If defined as 1, unsafe iterator use causes a runtime error. If defined as 0, checked iterators are disabled. The exact behavior of the runtime error depends on the value of _SECURE_SCL_THROWS. In debug mode, the default value for _SECURE_SCL is 1, meaning checked iterators are enabled. In release mode, the default value for _SECURE_SCL is 0.
http://msdn.microsoft.com/ko-kr/library/aa985896.aspx

_HAS_ITERATOR_DEBUGGING = 0
Defines whether the iterator debugging feature is enabled in a debug build. By default, iterator debugging is enabled.
http://msdn.microsoft.com/ko-kr/library/aa985939(v=VS.90).aspx

그외

/Z7, /Zi, /ZI (Debug Information Format)

Produces no debugging information, so compilation is faster.
비주얼 스튜디오 Property Pages - C/C++ - Debug Information Format을 기본 /ZI 에서 /Zi로 설정하면(Edit & Continue 기능을 끄면) 컴파일 속도와 실행속도를 향상시킨다.
http://msdn.microsoft.com/en-us/library/958x11bc(v=vs.80).aspx


1 2