데비안 계열에서만 동작할려는지 모르겠는데...
어쨌든 다음과 같이 해서 현재 사용중인 java에 대한 설정을 확인 할 수 있다. (옵션은 소문자 'L' 이다 )

$> update-java-alternatives -l
java-1.7.0-openjdk-amd64 1071 /usr/lib/jvm/java-1.7.0-openjdk-amd64

그러면 위와 같이 jdk 버전과 패스가 나온다.  이를 보고 필요에 따라   JAVA_HOME, JRE_HOME 을 설정하면 되겠다.

Posted by code cat
리눅스2014. 7. 14. 16:08

출처:https://developer.gnome.org/glib/unstable/glib-The-Main-Event-Loop.html

The GMainLoop data type represents a main event loop. 

A GMainLoop is created with g_main_loop_new()After adding the initial event sources, g_main_loop_run() is called. This continuously checks for new events from each of the event sources and dispatches them. Finally, the processing of an event from one of the sources leads to a call to g_main_loop_quit() to exit the main loop, andg_main_loop_run() returns.

'리눅스' 카테고리의 다른 글

samba 포트 포워딩  (0) 2014.08.26
파일 캐릭터 인코딩 바꾸기  (0) 2014.08.02
Alien을 이용한 RPM 패키지 인스톨  (0) 2014.07.02
sysroot  (0) 2014.03.14
[EXT4] noauto_da_alloc 옵션에 대해서  (0) 2013.11.25
Posted by code cat

file -bi file_name

하면 간단하게 다음과 같이 나온다.

text/x-c; charset=utf-8


Posted by code cat
리눅스2014. 7. 2. 14:18

우선 Alien을 받자.

sudo apt-get install alien

 

설치된 Alien을 통해 rpm 패키지를 설치해보자.

sudo alien -i package_name.rpm


너무 간단한가....

'리눅스' 카테고리의 다른 글

파일 캐릭터 인코딩 바꾸기  (0) 2014.08.02
GMainLoop 동작방식  (0) 2014.07.14
sysroot  (0) 2014.03.14
[EXT4] noauto_da_alloc 옵션에 대해서  (0) 2013.11.25
[EXT4] barrier=1 혹은 0에 대한 옵션 설명  (0) 2013.11.24
Posted by code cat
안드로이드2014. 6. 26. 15:29

어제 06/25일자 Google I/O를 라이브로 시청하게 됐는데, Android TV가 새롭게 단장을 하고 나왔다.
관련 이미지야 찾아보면 많으니 여긴 갔다 붙이진 않겠지만, 기존 Android TV와 다른 점은,

 

기존 Android TV가 스마트폰을 대형화 시킨 구조였다면, 이번 Android TV는 적어도 TV에 맞게 컨트롤 및 접근성에 대한 배려를 갖추고 나왔다고 하면 되겠다.

 

쉽게 말하자면, TV 패널은 터치가 되지 않는다. 그래서 스마트폰에서 어떤 앱을 실행시킬려는 시도나 특정 시나리오에 접근하려는 의도가 티비에서는 잘 되지 않는다. 아니, 개짜증난다.

리모콘으로 홈 메뉴 누르고, 스크롤해서 해서 어플에 접근한다고 해보자.  티비를 보는 사람은 그렇게 복잡한 과정을 원치 않는다.  쇼파에 누워서 몇번 클릭 클릭으로 혹은 단순한 채널 서핑 정도로 자기가 보고 싶은게 나와야 직성이 풀린다.

 

그래서 이번 Android TV는 적어도 데모영상만 봤을 때, 그러한 접근성과, 주변기기(스마트폰 + 웨어러블 디바이스(데모에서는 G와치로 구동시키는걸 보여줬다))를 통한 좀 더 익숙한(?) 컨트롤을 제공한다.   이건 확실히 올바른 방향으로 나아간다고 봐야 겠다.  아직 인터페이스가 썩 이쁘다고 하기엔 그랬다.  컨텐츠가 리스트되는 건 좋은데, 뒤의 티비 혹은 영상을 똬악 가리면서 나오는건 좀 더 처리가 필요하다고 보인다.

 

그리고, 게이밍을 강조한다고 했는데, 막상 보여준 게임은 NBA잼하고, 그 이름 뭐를 커비를 연상시키는 털 복숭이가 팡팡 뛰어다니는 게임(게임디테일은 매우 띄어나 보였다)밖에 없어서 아직 어떤 정도의 수준을 생각하는지는 모르겠다만, 벤더 리스트에 퀄컴이 있었던걸로 보아 제조사의 의지에 따라 요새 고성능 스마트폰에서 체감할 수 있는 정도의 성능을 보여줄 수도 있다고 본다.

 

아직은 갈길이 멀어보이지만, 구글이 이번 I/O를 통해서 IoT의 주도권을 가져가려는 의도는 확실히 보인다.  이는 기존 제조업체에서도 그리 반갑게 느껴지지는 않을 거라고 보인다.(정말 토스터 기에도 안드로이드를 깔아야 되는 시대는 그리 원치 않는다.) 참고로 셋톱박스 쪽에 레이져도 붙은걸 보니, 콘솔게이밍 디바이스+홈엔터테인먼트 기기로서의 포지션도 기대해볼만 하다.

'안드로이드' 카테고리의 다른 글

bionic linker  (0) 2013.09.10
Posted by code cat
프로그래밍/C2014. 6. 5. 09:17

for (i=0; i < size && iterator->next != NULL; i++, iterator=iterator->next)


for 문 조건처리에서는 위와 같이 &&나 ||를 써줘야 한다. 만약 대신에 ','를 쓴다면 


for (i=0; i < size, iterator->next != NULL; i++, iterator=iterator->next)


앞의 조건, i < size는 그냥 무시가 되어 버리니 조심하자.  하지만 처리 부분에서는 ','를 써서 처리하면 된다.

Posted by code cat
프로그래밍/C2014. 6. 2. 16:29

strerror

#include <stdio.h>

#include <string.h>


void main()

{

  FILE *fp;

  if ((fp = fopen("data.txt", "r")) == NULL) {

    fprintf(stderr, "ERROR: %s\n", strerror(errno));

    exit(1);

  }

  exit(0);

}


strerror는 errno를 받아서 실패한 원인에 대한 메세지를 리턴한다.


그런데 perror는 더 편리하다.

perror

#include <stdio.h>


void main()

{

  FILE *fp;

  if ((fp = fopen("data.txt", "r")) == NULL) {

    perror("ERROR");  // 오류가 발생했을 때 오류 출력시에 앞에 붙는 PREFIX를 인자로 받는다.

    exit(1);

  }

  exit(0);

}


Posted by code cat
프로그래밍/C2014. 5. 29. 11:22

출처: http://stackoverflow.com/questions/605845/do-i-cast-the-result-of-malloc

In this question, someone suggested in a comment that I should not cast the results of malloci.e:

int *sieve = malloc(sizeof(int)*length);

rather than:

int *sieve = (int *)malloc(sizeof(int)*length);

Why would this be the case?


No; you don't cast the result, since:

  • It is unnecessary, as void * is automatically and safely promoted to any other pointer type in this case.
  • It can hide an error, if you forgot to include <stdlib.h>. This can cause crashes, in the worst case.
  • It adds clutter to the code, casts are not very easy to read (especially if the pointer type is long).
  • It makes you repeat yourself, which is generally bad.

As a clarification, note that I said "you don't cast", not "you don't need to cast". In my opinion, it's a failure to include the cast, even if you got it right. There are simply no benefits to doing it, but a bunch of potential risks, and including the cast indicates that you don't know about the risks.

Also note, as commentators point out, that the above changes for straight C, not C++. I very firmly believe in C and C++ as separate languages.

To add further, your code needlessly repeats the type information (int) which can cause errors. It's better to dereference the pointer being used to store the return value, to "lock" the two together:

int *sieve = malloc(length * sizeof *sieve);

This also moves the length to the front for increased visibility, and drops the redundant parentheses with sizeof; they are only needed when the argument is a type name. Many people seem to not know (or ignore) this, which makes their code more verbose. Remember: sizeof is not a function! :)


@sirgeorge - without the prototype/decl (in stdlib.h), a C compiler might/will assume that malloc returns an int. Then the compiler generates code for the call in question as if it is getting an int. Then, say, you are compiling for a platform where pointers and ints do not have the same size, and you cast the returning int into a pointer. Bad juju. And the compiler, upon seeing the casting, won't give you a warning in this case. But if you don't cast it, then the compiler will complain abou the int-to-ptr assignment (and you will be able to detect the missing include for stdlib.h) –  luis.espinal Mar 14 '12 at 19:28 

'프로그래밍 > C' 카테고리의 다른 글

for 문 multiple 조건 & 처리  (0) 2014.06.05
strerror 사용법, perror 사용법  (0) 2014.06.02
strtok에 NULL을 전달하는 이유  (0) 2014.05.29
함수포인터 & typdef를 이용한 함수포인터  (0) 2014.05.07
ternary operator  (0) 2014.04.13
Posted by code cat
프로그래밍/C2014. 5. 29. 09:32

strtok를 쓸 때, 왜 두번째 콜에서 NULL을 넘겨줄까? 그냥 그러려다 찾아보았다.


char str[] = "Hello World. How are you?";
        char delim[] = " ";
        char *ptr;

ptr = strtok(str, delim);
        printf("%s\n", ptr);
        while(ptr = strtok(NULL, delim))
            printf("%s\n", ptr);


다음은 strtok.c 의 내용이다.(glibc 2.19버전)


18 #include <string.h>
19 
20 
21 static char *olds;
22 
23 #undef strtok
24 
25 /* Parse S into tokens separated by characters in DELIM.
26  If S is NULL, the last string strtok() was called with is
27  used. For example:
28  char s[] = "-abc-=-def";
29  x = strtok(s, "-"); // x = "abc"
30  x = strtok(NULL, "-="); // x = "def"
31  x = strtok(NULL, "="); // x = NULL
32  // s = "abc\0=-def\0"
33 */
34 char *
36  char *s;
37  const char *delim;
38 {
39  char *token;
40 
41  if (s == NULL)
42  s = olds;
43 
44  /* Scan leading delimiters. */
45  s += strspn (s, delim);
46  if (*s == '\0')
47  {
48  olds = s;
49  return NULL;
50  }
51 
52  /* Find the end of the token. */
53  token = s;
54  s = strpbrk (token, delim);
55  if (s == NULL)
56  /* This token finishes the string. */
57  olds = __rawmemchr (token, '\0');
58  else
59  {
60  /* Terminate the token and make OLDS point past it. */
61  *s = '\0';
62  olds = s + 1;
63  }
64  return token;
65 }


41라인을 보면 NULL일 경우, static 변수 old로 대체한다. 아! 그래서 NULL을 써서 이어서 파싱이 되게 하는구나.  그리고 static변수라... 쓰레드 사용시에 문제가 있을 거 같다.

추가로 찾아본 내용을 보니,(http://ogoons.tistory.com/m/post/70) 다음과 같은 주의사항이 있다.


1. strtok()의 사용 후, 원본 문자열의 데이터를 보장할 수 없다.
2. visual studio 상위 버전에 문제가 있을 수 있다.
3. strtok()은 내부적으로 문자열 분리를 위해 static변수를 놓고 정적공유를 함으로 , thread-safe하지 않다.(음 역시)


따라서 위의 상황들을 개선한 strtok_s()를 쓰길 권장한다고 한다.


char str[] = "Hello World Good, Morning Sunshine";

char delim[] = " ,";

char *ptr;

char *context = NULL;

ptr = strtok_s(str, delim, &context);

printf("%s\n", ptr);

while(ptr = strtok_s(NULL, delim, &context))

printf("%s\n", ptr);


Posted by code cat
프로그래밍/C2014. 5. 7. 15:33


if 0로 묶여 있는 부분은 보통의 함수포인터를 부르는 방식이다.
하지만 이는 복잡해 보이고 혼란을 줄 수 있는 모양일 수 있다.  따라서 코드를 깔끔하게 보이기 위해 else로 묶여있는 부분을 보면 typedef를 통한 함수포인터 사용을 볼 수 있다.


typedef에 대한 부분이 혼란스러우면 아래와 같이 이해하면 좋다(출처:https://kldp.org/node/119822)

typedef를 빼면 변수 선언 붙이면 타입 선언이라고 이해하시면 편합니다.

unsigned int u32; // u32는 unsigned int 타입의 변수
typedef unsigned int u32; // u32는 unsigned int 타입

int (*func)(int, int); // func는 (int, int)를 받고 int를 리턴하는 함수에 대한 포인터 타입의 변수
typedef int (*func)(int, int); // func는 (int, int)를 받고 int를 리턴하는 함수에 대한 포인터 타입


'프로그래밍 > C' 카테고리의 다른 글

malloc 를 캐스팅 하지 말자.  (0) 2014.05.29
strtok에 NULL을 전달하는 이유  (0) 2014.05.29
ternary operator  (0) 2014.04.13
[visual studio] 에러 C2143 로컬변수 선언 위치  (0) 2013.11.24
c precedence table  (0) 2013.11.23
Posted by code cat