프로그램 사용/gcc2010. 1. 27. 17:18
#if 문이라던가 각종 전처리기용 문구들은
여러가지 확장을 통해서 컴파일을 하기 때문에 source insight 등의 힘을 빌려도 분석하기 어려운 면이 있다.

일반적으로 컴파일러는 전처리기 - 컴파일 - 어셈블 - 링크 과정을 거치는데(아마도?)
전처리기 까지만 거친 결과를 stdout 으로 출력해준다.

$ man gcc
       -E  Stop after the preprocessing stage; do not run the compiler proper.
            The output is in the form of preprocessed source code, which is sent to the standard output.

           Input files which don't require preprocessing are ignored.

[링크 : http://linux.die.net/man/1/gcc]

$ cat test.c
#if 1
int test;
#else
int tt;
#endif

int main()
{
        return 0;
}

$ gcc -E test.c
# 1 "test.c"
# 1 "<built-in>"
# 1 "<command-line>"
# 1 "test.c"

int test;




int main()
{
 return 0;
}


#include 하는 모든 파일을 확장하기 때문에, #include <stdio.h>만 해도 내용이 엄청 길어진다.
그리고 줄단위로 처리하기 때문에 사라진 #if 문 대신 엔터만 남아 위와 같이 휑~하게 나왔다.


[링크 : http://cafe.naver.com/devctrl/949]
Posted by 구차니
프로그램 사용/gcc2009. 9. 21. 21:33
--sysroot=dir
    Use dir as the logical root directory for headers and libraries. For example, if the compiler would normally search for headers in /usr/include and libraries in /usr/lib, it will instead search dir/usr/include and dir/usr/lib.

    If you use both this option and the -isysroot option, then the --sysroot option will apply to libraries, but the -isysroot option will apply to header files.

    The GNU linker (beginning with version 2.16) has the necessary support for this option. If your linker does not support this option, the header file aspect of --sysroot will still work, but the library aspect will not.

-isysroot dir
    This option is like the --sysroot option, but applies only to header files.  See the --sysroot option for
    more information.

[링크 : http://linux.die.net/man/1/gcc]

기본값은 /usr/include 인데, -sysroot로 기본 디렉토리를 변경 시키면
<stdio.h> 와 같은 파일도 찾지 못해 link 에러를 발생시키며 컴파일이 실패된다.

$ more test.c
#include <stdio.h>

int main(int argc, char **argv)
{
        printf("hello world\n");
        return 0;
}

$ gcc --sysroot=/ test.c
/usr/bin/ld: this linker was not configured to use sysroots
collect2: ld returned 1 exit status



아무튼, 크로스컴파일과 같이 특정 include 디렉토리를 사용해야 할 경우,
--sysroot 를 이용해서 변경하면 될 듯 하다
Posted by 구차니
프로그램 사용/gcc2009. 5. 28. 23:06
오늘 희한한 switch - case문을 들었다

case 1 ... 10:

이런식으로 기존에는
case 1:
case 2:
...
case 9:
case 10:
이라고 쓰던것을 줄여 쓸수 있다고 한다.

검색을 해보니 c#과 gcc에서 지원하고 C99 등에는 검색이 걸려 나오지 않는다.
정체가 머냐?


[링크 : http://www.devnewsgroups.net/group/microsoft.public.dotnet.framework/topic62939.aspx]
[링크 : http://www.devhood.com/messages/message_view-2.aspx?thread_id=13708]
Posted by 구차니
프로그램 사용/gcc2009. 2. 18. 17:13
char str[] = "Hello world!";

만약에 키보드로는 입력 불가능한 control chacter(제어문자)를 문자열 상에 넣고 싶으면 어떻게 해야 할까?
일단 가장 흔히 쓰는 제어문자로는

\t
\n

인데, 자신이 직접 헥사로 넣고 싶다면

\x20

이런식으로 입력을 하면된다.


덧 : 개인적으로는 ISO8859 용 스트링의 첫 바이트에 들어 가는 제어문자를 넣는 방법으로 활용하고 있다.
덧2: 솔찍히 이실직고 하자면, 직접해보니 오작동을 하는 경향이 보인다.
      비쥬얼 스튜디오나 일반 gcc 에서도 테스트를 해봐야겠다.
Posted by 구차니