프로그래밍/C++2013. 8. 4. 19:31
예제: Teach yourself C++ in 21 days
Posted by code cat

다음의 명령어를 사용하면 된다.

 

dpkg --get-selections


Posted by code cat
리눅스/커널2013. 7. 25. 09:19

 

Kernel oops시에 나오는 taint 종류는 다음과 같다.(kernel/panic.c)

 

187 static const struct tnt tnts[] = {
188         { TAINT_PROPRIETARY_MODULE,        'P', 'G' },
189         { TAINT_FORCED_MODULE,                 'F', ' ' },
190         { TAINT_UNSAFE_SMP,                       'S', ' ' },
191         { TAINT_FORCED_RMMOD,                 'R', ' ' },
192         { TAINT_MACHINE_CHECK,                 'M', ' ' },
193         { TAINT_BAD_PAGE,                           'B', ' ' },
194         { TAINT_USER,                                  'U', ' ' },
195         { TAINT_DIE,                                     'D', ' ' },
196         { TAINT_OVERRIDDEN_ACPI_TABLE,   'A', ' ' },
197         { TAINT_WARN,                                 'W', ' ' },
198         { TAINT_CRAP,                                 'C', ' ' },
199         { TAINT_FIRMWARE_WORKAROUND,   'I', ' ' },
200         { TAINT_OOT_MODULE,                    'O', ' ' },
201 };

'리눅스 > 커널' 카테고리의 다른 글

[커널] FB 문서  (0) 2013.12.09
[안드로이드][커널]Unknown symbol _GLOBAL_OFFSET_TABLE_  (0) 2013.08.09
[OS] priority inversion 해결방법  (0) 2013.01.13
monolithic vs microkernel  (0) 2013.01.13
VFS(1) -구조체-  (0) 2012.12.08
Posted by code cat

오랜만에 쓰는 screen/byobu 글이다.

가끔 screen에서 여러개 창을 쓰다가 중간 걸 꺼버릴 때가 있다.


0@$bash 1@$bash 2@$bash 3@$bash 4@$bash 


저렇게 있음, 3번을 꺼 버릴 때가 있다. 그럼 


0@$bash 1@$bash 2@$bash 4@$bash 


0,1,2,4 이렇게 쓰는데, 먼가 좀 그렇다.

한동안 그려러니 하고 쓰다 맘먹고 찾아본 결과 숫자를 바꾸는 법을 알아냈다.


바꾸려는 윈도우(4번이겠지)에 가서

ctrl + a, :number 3

하면 4번 윈도우가 3번으로 바뀌어서,

0@$bash 1@$bash 2@$bash 3@$bash


로 바뀐다.


정식 방법은

ctrl + a, :number x


로 바꿀 숫자를 x에 넣으면 된다.


하하 속 시원하다.

Posted by code cat

os.path.basename(path)

 

>>>path="out/target/product/codecat/abc.txt"

>>>import os

>>>os.path.basename(path)

'abc.txt'

 

os.path.dirname(path)

 

>>>path="out/target/product/codecat/abc.txt"

>>>import os

>>>os.path.dirname(path)

'out/target/product/codecat'

'리눅스 > 스크립트/유틸' 카테고리의 다른 글

ubuntu에 설치된 패키지 리스트 보기  (0) 2013.07.25
[screen/byobu] 윈도우 숫자 바꾸기  (0) 2013.06.29
python, regular expression match  (0) 2013.04.28
python, tempfile.mkdtemp  (0) 2013.04.28
python, getopt  (0) 2013.04.21
Posted by code cat
프로그래밍/C++2013. 5. 26. 11:31
What is the difference between a null pointer and a stray pointer? 

Answer: When you delete a pointer, you tell the compiler to free the memory, but the pointer itself continues to exist. It is now a stray pointer. When you then write myPtr = 0; you change it from being a stray pointer to being a null pointer. Normally, if you delete a pointer and then delete it again, your program is undefined. That is, anything might happen—if you are lucky, the program will crash. If you delete a null pointer, nothing happens; it is safe. Using a stray or a null pointer (for example, writing myPtr = 5;) is illegal, and it might crash. If the pointer is null, it will crash, another benefit of null over stray. Predictable crashes are preferred because they are easier to debug
Posted by code cat

git이 쓰다가 꼬이면 에라씨! 하고

 

git reset --hard HEAD^

 

등을 날릴 때가 있는데, 실행하고 나서 앗차!! 할 때가 있다.

 

이럴 땐 침착하게 다음과 같이 커맨드를 날리자.

git reflog

 

무언가 history가 쫘악 뜬다. 여기서 내용을 보면 방금 날린 git reset에 대한 내용이 있다.

그럼 바로 그 전에 걸로 돌아가보자.

git reset HEAD@{1}

 

오! 된다. 이제 reset잘못했다가 절망하지 말자.

Posted by code cat
프로그래밍/C++2013. 5. 18. 19:42
int *p1;
struct employee{
  char name[20];
  int age;
  float sal;
} *p2;

p1 = new int;  //allocates 4 bytes
p2 = new employee; //allocates 32? bytes

int *p3;
p3 = new int[30];  //allocates memory for storing 30 inters

delete p1;
delete p2;
delete [] p3;

에 비해, malloc/free를 쓴다면....

p1 = (int*) malloc (sizeof(int));
p2 = (struct employee*) malloc (sizeof(struct employee));
p3 = (int*) malloc (sizeof(int) * 30);

malloc은 void 타입을 리턴하기 때문에, typecasting도 해 줘야 하고,  new의 경우, array dimension을 지원한다.  물론 variable dimension(dynamic size)도 지원한다.
훨씬 낫지 않은가?

그렇다면 new / free, malloc / delete 이런 조합도 가능할가? 안된다.

한가지 더...
new/delete는 오브젝트들을 생성/파괴 할 수 있는 반면, malloc/free는 메모리를 할당/해제 한다.  이는 중요한 부분으로 클래스 생성/파괴에서 new/delete을 쓰는 이유이다.
Posted by code cat
프로그래밍/C++2013. 5. 11. 14:53

c에서 c++함수 호출 시에 역시 extern "c"를 사용하게 되는데, 우선 예를 보자.

 

// gcd.h

#ifdef __cplusplus

extern "C"

#endif

int gcd(int v1, int v2);

 

//gcd.cpp

#include <boost/math/common_factor.hpp>

#include "gcd.h"

extern "C" {

int gcd(int v1, int v2){

return boost::math:gcd(v1, v2);

}

}

 

//sample.c

#include <stdio.h>

#include "gcd.h"

int main()

{

printf("%d와 %d의 최대공약수는 %d(이)다.\n", 14, 35, gcd(14,35));

return 0;

}

 

(위의 예문은 "BINARY HACKS 해커가 전수하는 테크닉 100선, 진명조 옮김" page 74 ~ page 75에서 발췌한 내용이다.)

뭐 다 좋은데, C++에서 저렇게 extern "C"를 함수에 추가해 줄 수 있는 경우가 과연 많을까?  본인 경험상 라이브러리 함수로 받아 수정을 못하는 경우가 태반인데, 과연 저렇게 수정해서 쓸 수 있는 경우가 많을까 고민이다.

 

뭔가 잘못 알고 있는 건 아닐까? 누가 알면 알려줬으면 좋겠다.

Posted by code cat
프로그래밍/C++2013. 5. 11. 12:09

C++에서 C라이브러리 혹은 프로그램 링크시에 우리는 보통 다음과 같이 쓴다

 

extern "C" 함수리턴타입 함수이름(매개변수원형);

 

그런데 이걸 C에서 쓰듯 함수 콜 직전에 불러준다거나 하면(그리 추천하는 방법은 아니다)

 

'expected unqualified-id before string constant' 

 

라는 GR같은 에러가 난다.

이건 C++에서는 클래스 정의나 함수구현 부분에서 "C"코드를 허락하지 않기 때문이다.

 

Posted by code cat