본문 바로가기
코딩취미/C,C++

[C언어] C11 : ISO/IEC 9899:2011 특징과 내용

by 브링블링 2023. 12. 13.
728x90

C11 :  ISO/IEC 9899:2011

C11는 C 언어의 표준인 ISO/IEC 9899:2011 표준을 나타냅니다. 이 표준은 2011년에 제정되었으며, 이전의 C99 표준을 대체하고 확장하는 업데이트를 제공합니다.

C11 의 특징과 내용

C11는 기존의 C 표준을 더 나은 표준 라이브러리, 향상된 특징 및 더 많은 확장과 함께 업데이트했습니다. C 프로그래머에게 더 많은 도구와 선택지를 제공하여 효율적이고 안전한 프로그래밍을 할 수 있도록 돕고 있습니다.

특 징 설 명 예제 코드
Atomic
Operations
원자 연산을 위한 표준 라이브러리 함수인 <stdatomic.h>가 추가되었습니다. c #include <stdatomic.h> int main() { atomic_int counter = ATOMIC_VAR_INIT(0); atomic_fetch_add(&counter, 1); return 0; }
Thread
-Safe
Functions
멀티스레딩 환경에서 안전한 함수들이 추가되었습니다. c #include <threads.h> int main() { mtx_t mutex; mtx_init(&mutex, mtx_plain); // ... Perform thread-safe operations mtx_destroy(&mutex); return 0; }
Bounds
-Checking
인덱스 경계 검사를 위한 안전한 함수들이 추가되었습니다. c #define __STDC_WANT_LIB_EXT1__ 1 #include <string.h> int main() { char dest[10]; char src[20]; strcpy_s(dest, sizeof(dest), src); return 0; }
Static
Assertions
정적 어설션을 지원하는 _Static_assert 키워드가 도입되었습니다. c _Static_assert(sizeof(int) == 4, "int must be 32 bits");
Type
Generics
제네릭 프로그래밍을 위한 _Generic 키워드가 도입되었습니다. c #include <stdio.h> #define print(x) _Generic((x), int: printf("%d\n", x), float: printf("%f\n", x)) int main() { int i = 42; float f = 3.14; print(i); print(f); return 0; }
Anonymous
Structures
익명 구조체가 도입되어 구조체를 정의하면서 인스턴스를 생성하는 기능이 추가되었습니다. c struct { int x; int y; } point; point.x = 1; point.y = 2;
Multithreading
Support
멀티스레딩과 관련된 표준 라이브러리 함수들이 추가되었습니다. c #include <threads.h> thrd_t thread; thrd_create(&thread, my_function, NULL);
Bounds-Checking Interface 배열 경계 검사를 위한 표준 라이브러리 함수들이 추가되었습니다 (<stdnoreturn.h>). c #define __STDC_WANT_LIB_EXT1__ 1 #include <stdio.h> int main() { int arr[5] = {1, 2, 3, 4, 5}; for (size_t i = 0; i < sizeof(arr) / sizeof(arr[0]); i++) { printf("%d\n", bounds_safe(arr, i)); } return 0; }
Static
Alignment
_Alignas 키워드가 추가되어 정적으로 변수의 정렬을 지정할 수 있습니다. c struct alignas(16) AlignedStruct { int a; float b; };
Dynamic
Alignment
_Alignof 키워드가 추가되어 런타임에 변수의 정렬을 확인할 수 있습니다. c printf("Alignment of int: %zu\n", alignof(int));

 

728x90