#if 조건
#ifdef 정의되었을 경우
#ifndef 정의되지 않았을 경우
#else 그외의 경우
#elif 그 외의 조건일 경우
#endif 조건문 전처리기의 끝
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | #include <stdio.h> #define VERSION 1 int main(void) { #ifdef VERSION #if VERSION <2 printf("VERSION >2\n"); #else printf("VERSION :%d\n",VERSION); #endif #else printf("Unknown VERSION\n"); #endif return 0; } | cs |
1 2 3 4 5 6 7 8 9 10 11 12 13 | #include <stdio.h> int main(void) { #ifndef __linux__ printf("not linux\n"); #else printf("linux\n"); #endif return 0; } | cs |
<그림 2> 리눅스인지 확인
__linux__는 linux인지 아닌지 확인하는 매크로임
리눅스임
1 2 3 4 5 6 7 8 | #ifndef _18_H #define _18_H struct data { int a; }; #endif | cs |
<그림.3> ex.5.h
1 2 3 4 5 6 7 8 | #include "ex.5.h" #include "ex.5.h" int main(void) { return 0; } | cs |
<그림 4> ex.5.c
'c언어' 카테고리의 다른 글
void형 포인터 (0) | 2016.08.09 |
---|---|
구조체 (0) | 2016.08.08 |
정보 올림피아드 - 147 (0) | 2016.08.03 |
정보 올림피아드 - 146 (0) | 2016.08.02 |
정보 올림피아드 - 145 (0) | 2016.08.02 |