C언어 #ifdef DEBUG

1 개요[ | ]

GCC #ifdef DEBUG
C언어 #ifdef DEBUG
  • #ifdef DEBUG ~ #endif 사이의 코드는 디버깅시에만 실행하도록 한다.
  • gcc로 컴파일할 때 -DDEBUG 옵션을 붙이면 디버깅하고, 옵션이 없으면 무시된다.

2 실습[ | ]

  • hello_debug.c
#include <stdio.h>
int main() {

#ifdef DEBUG
	printf("DEBUG!!!!\n");
#endif
	printf("Hello World\n");
	return 0;
}
root@zetawiki:~# gcc hello_debug.c
root@zetawiki:~# ./a.out
Hello World
root@zetawiki:~# gcc hello_debug.c -DDEBUG
root@zetawiki:~# ./a.out
DEBUG!!!!
Hello World

3 같이 보기[ | ]

4 참고[ | ]

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}