기본 콘텐츠로 건너뛰기

2013의 게시물 표시

C 표준, GCC 그리고 컴파일 옵션

GCC supports three versions of the C standard, although support for the most recent version is not yet complete. The original ANSI C standard (X3.159-1989) was ratified in 1989 and published in 1990. This standard was ratified as an ISO standard (ISO/IEC 9899:1990) later in 1990. There were no technical differences between these publications, although the sections of the ANSI standard were renumbered and became clauses in the ISO standard. This standard, in both its forms, is commonly known as  C89 , or occasionally as  C90 , from the dates of ratification. The ANSI standard, but not the ISO standard, also came with a Rationale document. To select this standard in GCC, use one of the options  -ansi ,  -std=c90  or  -std=iso9899:1990 ; to obtain all the diagnostics required by the standard, you should also specify  -pedantic  (or  -pedantic-errors  if you want them to be errors rather than warnings). See  Options Controlling C Dialect . Errors in the 1990 ISO C standard were cor

iso646.h

iso646.h 파일은 일부 연산자에 사용되는 기호들을 사용하기 힘든 환경에서 이를 영문자로 대체하기 위한 목적으로 사용된다. (한글 키보드에서는 이런 문자들이 쉽게 입력 가능하므로 그닭...) 다음과 같이 11가지의 매크로가 정의되어 있다. #define   and             && #define   and_eq       &= #define   bitand       & #define   bitor          | #define   compl          ~ #define   not            ! #define   not_eq       != #define   or             || #define   or_eq          |= #define   xor            ^ #define   xor_eq       ^= #include   <stdio.h> #include   <iso646.h> void   alternativeANDOperator (   int   num) {           const   int   a = 0;           const   int   b = 10;           if   (num > a and num < b) {   /*   num   > a &&   num   < b */                  printf ( "%d < %d < %d"   , a, num, b);        } } int   main () {           int   num = 5;        alternativeANDOperator(num);           return   0; }

float.h

float.h 파일은 부동소수값을 나타내는데 필요한 요소들의 최대, 최소값 등을 나타내는 매크로 상수들로 구성되어 있다. 부동 소수값은 부호(+, -)와 함께 다음과 같은 요소들로 구성된다. (매크로 상수의 이름으로 사용되는 부분은 대문자로 표시하였다.) MANTissa  *  RADIX EXPonent #include   <stdio.h> #include   <float.h> void   floatingPointInfo () {           printf ( "Radix: %d\n"   , FLT_RADIX);           printf ( "Precision of Mantissa: %d\n"   , FLT_MANT_DIG);           printf ( "Minimum Exponent: %d\n"   , FLT_MIN_EXP);           printf ( "Maximum Exponent: %d\n"   , FLT_MAX_EXP);           printf ( "Minimum Float: %e\n"   , FLT_MIN);           printf ( "Maximum Float: %e\n"   , FLT_MAX);           printf ( "Minimum Double: %e\n"   , DBL_MIN);           printf ( "Maximum Double: %e\n"   , DBL_MAX);           printf ( "Rounding behavior: "   );           switch   (FLT_ROUNDS) {           case   0:                  printf ( "tow

assert.h

assert.h 파일은 프로그래밍 단계에서 오류 검증 목적으로 사용되는 assert()라는 매크로 함수 단 하나만을 정의하고 있다. 단, 소스 파일에 NDEBUG가 정의되어 있는 때에는 작동하지 않는데, NDEBUG는 다음과 같이 정의한다. #define NDEBUG assert ( expression ) assert()는 디버깅의 용도로 사용되는데 매개변수 값이 0 (즉, false)인 경우에 프로그램을 중단하고 다음과 유사한 디버깅 정보를 출력한다. Assertion failed: num!=NULL, file ..\src\assert_test.c, line 7 #include   <stdio.h> #include   <assert.h> /* #define NDEBUG */ void   printNumber (   int * num) {        assert(num!=NULL);   /*  num 이 널이면 프로그램을 중단한다. */           printf ( "%d\n"   , *num); } int   main () {           int   i = 10;           int * m = NULL;           int * n = NULL;        m = &i;        printNumber(m);        printNumber(n);           return   0; }

errno.h

errno.h 파일에는 오류 코드를 기억할 수 있는 errno가 매크로로 정의되어 있고, 그 외에 각종 오류 코드 넘버들이 매크로 상수로 정의되어 있다. 프로그램 시작시에는 errno의 값이 0으로 초기화되며, 특정 오류가 발생한 때에는 이 값이 해당 오류 코드로 바뀐다. 프로그램에서도 이 값을 읽거나 수정할 수 있다. #include   <stdio.h> #include   <errno.h> int   main () {           printf ( "%d\n"   , errno);        errno = ENOMEM;           printf ( "%d\n"   , errno);           return   0; }    

ctype.h

ctype.h 파일에는 문자의 종류를 판별( is...() )하거나 대소문자를 변경( to...() )하는 함수들이 정의되어 있다. int  isalnum (int ch); 문자 ch가 영문자 혹은 숫자인 경우에는 0이 아닌 값 (즉, true)를 반환하고, 그렇지 않은 때에는 0 (false)를 반환한다. 매개변수 ch는 int 형으로 형변환된다. A ~ Z, a~ z, 0 ~ 9 int  isalpha (int ch); 문자 ch가 영문자인 경우에는 0이 아닌 값 (즉, true)를 반환하고, 그렇지 않은 때에는 0 (false)를 반환한다. 매개변수 ch는 int 형으로 형변환된다. A ~ Z, a ~ z int  iscntrl (int ch); 문자 ch가 제어문자인 경우에는 0이 아닌 값 (즉, true)를 반환하고, 그렇지 않은 때에는 0 (false)를 반환한다. 매개변수 ch는 int 형으로 형변환된다. 0x00 ~ 0x1f, 0x7f int  isdigit (int ch); 문자 ch가 10진수 숫자인 경우에는 0이 아닌 값 (즉, true)를 반환하고, 그렇지 않은 때에는 0 (false)를 반환한다. 매개변수 ch는 int 형으로 형변환된다. 0 ~ 9 int  isgraph (int ch); 문자 ch가 표현 가능한 문자인 경우에는 0이 아닌 값 (즉, true)를 반환하고, 그렇지 않은 때에는 0 (false)를 반환한다. 매개변수 ch는 int 형으로 형변환된다. 출력 가능한 문자 집합에서 공백 문자가 제외된다. 0x21 ~ 0x7e int  islower (int ch); 문자 ch가 소문자인 경우에는 0이 아닌 값 (즉, true)를 반환하고, 그렇지 않은 때에는 0 (false)를 반환한다. 매개변수 ch는 int 형으로 형변환된다. a ~ z int  isprint (int ch); 문자 ch가 영문자 혹은 숫자인 경