Slide 1

Slide 1 text

ࠓ೔͔Β࢖͑ΔC11 naruse

Slide 2

Slide 2 text

C Standards w ,3 w $ $3VCZ͸ݪଇ$ͱ͞Ε͍ͯΔ w $ w $ w $Y

Slide 3

Slide 3 text

C99ͷ৽ػೳ • ΠϯϥΠϯؔ਺ • Mixed declarations and code • enumએݴͰͷ৑௕ͳΧϯ Ϛ • Մม௕഑ྻ • ՄมҾ਺ϚΫϩ • //ίϝϯτ • __func__ • long long, intXX_t,boolͳͲ ͷܕ • snprintfͳͲͷؔ਺ • ܕ૯শ਺ֶؔ਺ (tgmath.h)

Slide 4

Slide 4 text

C11 Changes • conditional (optional) features (including some that were previously mandatory) • support for multiple threads of execution including an improved memory sequencing model, atomic objects, and thread-local storage ( and ) • additional floating-point characteristic macros (<float.h>) • querying and specifying alignment of objects (, ) • Unicode characters and strings () (originally specified in ISO/IEC TR 19769:2004) • type-generic expressions • static assertions • anonymous structures and unions • no-return functions • macros to create complex numbers () • support for opening files for exclusive access • removed the gets function () • added the aligned_alloc, at_quick_exit, and quick_exit functions () • (conditional) support for bounds-checking interfaces (originally specified in • ISO/IEC TR 24731−1:2007) • (conditional) support for analyzability

Slide 5

Slide 5 text

C11 • getsͷ࡟আ • Bounds-checking interfaces • fopen(“foo.txt”,”wx”) • _Alignas, alignof, aligned_alloc • _Noreturn • _Generic • threads.h • stdatomic.h • ແ໊ߏ଄ମɾແ໊union • _Static_assert

Slide 6

Slide 6 text

getsͷ࡟আ • 2007೥ʹඇਪ঑ͱͳ͍͕͍ͬͯͨͭʹ࡟আ • char *gets(char *s); • ‘\n’·ͰಡΈࠐΉ • → ֬อ͢΂͖όοϑΝͷ௕͕͞ࣄલʹΘ͔Βͳ͍ • →όοϑΝΦʔόʔϥϯෆՄආ

Slide 7

Slide 7 text

Bounds-checking interfaces • ෟଐॻK (normative) • rsize_tܕ • _sγϦʔζ

Slide 8

Slide 8 text

rsize_t • sizeof(rsize_t) == sizeof(size_t) • RSIZE_MAX͸(SIZE_MAX >>1)΍࠷΋େ͖ͳ ΦϒδΣΫτͷαΠζΛఆٛ͢Δ͜ͱ͕ਪ঑ • https://www.jpcert.or.jp/sc-rules/c-int01-c.html

Slide 9

Slide 9 text

_sγϦʔζ • Microsoft༝དྷ (͕ͩ࣌ʑطଘͷMSͷͱએݴ͕ ҧ͏) • ISO/IEC TR 24731-1ΛܦͯෟଐॻKʹऩ࿥ • 70ݸͷ*_sͱ͍͏໊લͷؔ਺

Slide 10

Slide 10 text

• abort_handler_s • asctime_s • bsearch_s • ctime_s • fopen_s • fprintf_s • freopen_s • fscanf_s • fwprintf_s • fwscanf_s • getenv_s • gets_s • gmtime_s • ignore_handler_s • L_tmpnam_s • localtime_s • mbsrtowcs_s • mbstowcs_s • memcpy_s • memmove_s • memset_s • printf_s • qsort_s • scanf_s • set_constraint_h andler_s • snprintf_s • snwprintf_s • sprintf_s • sscanf_s • strcat_s • strcpy_s • strerror_s • strerrorlen_s • strncat_s • strncpy_s • strnlen_s • strtok_s • swprintf_s • swscanf_s • TMP_MAX_S • tmpfile_s • tmpnam_s • vfprintf_s • vfscanf_s • vfwprintf_s • vfwscanf_s • vprintf_s • vscanf_s • vsnprintf_s • vsnwprintf_s • vsprintf_s • vsscanf_s • vsnprintf_s • vsnwprintf_s • vsprintf_s • vsscanf_s • vswprintf_s • vswscanf_s • vwprintf_s • vwscanf_s • wcrtomb_s • wcscat_s • wcscpy_s • wcsncat_s • wcsncpy_s • wcsnlen_s • wcsrtombs_s • wcstok_s • wcstombs_s • wctomb_s • wmemcpy_s • wmemmove_s • wprintf_s • wscanf_s

Slide 11

Slide 11 text

fopen( , “x”) • open(2) (POSIX)ʹ͋ΔO_EXCLͷɺfopen൛ • wx, wbx, w+x, w+bx, wb+x • ϑΝΠϧ͕طʹ͋ͬͨΒΤϥʔʹ͢Δ

Slide 12

Slide 12 text

ΞϥΠϝϯτؔ࿈ • _Alignas (alignas): __attribute__((align)) Ͱ͢ • _Alignof (alignof): __alignof__Ͱ͢ • ׅހ಺ͷ໊લ͸ stdalign.h • ͲͪΒ΋GCC 2.95Ͱ͢Ͱʹ͋Δ

Slide 13

Slide 13 text

aligned_alloc • posix_memalignͰ͢ɻ • kosaki͞Μ͕ৄ͍͠ͷͰͦͬͪΛݟ·͠ΐ͏ • http://www.slideshare.net/kosaki55tea/glibc-malloc • https://www.youtube.com/watch?v=0-vWT-t0UHg

Slide 14

Slide 14 text

_Noreturn • __attribute__((noreturn))Ͱ͢ɻ

Slide 15

Slide 15 text

_Generic • ΅͘ͷߟ͑ͨ࠷ڧͷtgmath.hΈ͍ͨͳϥΠϒϥϦ Λͭ͘ΕΔ • __builtin_choose_exprͱ __builtin_types_compatible_pͱ__typeof__Ͱ࡞ΕΔ • ࣮͸__typeof__͚ͩͰͭ͘ΕΔʂ

Slide 16

Slide 16 text

threads.h εϨουϩʔΧϧετϨʔδ • _Thread_localهԱҬࢦఆࢠ (__thread) • ม਺໊ʹ͚ͭΔ͚ͩͰεϨουϩʔΧϧʹͳΔ • tss_create/tss_delete/tss_set/tss_get • POSIXͷTLSΈ͍ͨͳAPI΋͋Δ • pthread_key_create/pthread_key_delete/pthread_setspecific/ pthread_getspecific

Slide 17

Slide 17 text

threads.h εϨουAPI • pthread APIͷ໊લΛม͚͑ͨͩ • pthread_* → thrd_* • pthread_mutex_* → mtx_* • pthread_cond_* → cond_*

Slide 18

Slide 18 text

atomic • ݴޠϨϕϧ: _Atomicܕम০ࢠ • ؔ਺: atomic_* • (GCCͷ__atomic_*ͱ͸ҟͳΔ)

Slide 19

Slide 19 text

·ͱΊ • C99͸จ๏ͷมߋ͕ଟ͔ͬͨ • Ͱ΋࠷ۙͷ͸͍͍ͩͨαϙʔτ͍ͯ͠Δ • C11͸จ๏ͷมߋ͸গͳ͍ • จ๏ͷมߋΛ࢖Θͳͯ͘΋ಉ͜͡ͱ͕ग़དྷΔ • ͭ·ΓɺC11ͷػೳ͸(configureͱ͔Ͱ͕Μ͹Ε͹)ࠓ೔͔ Β࢖͑Δʂ

Slide 20

Slide 20 text

ͦͷଞ • __builtin_constant_p • __builtin_unreachable • __builtin_types_compatible_p • __builtin_choose_expr • __builtin_expect • https://gcc.gnu.org/onlinedocs/gcc/Other-Builtins.html • __has_builtin, __has_feature, __has_extension, __has_attribute, __has_include • http://clang.llvm.org/docs/LanguageExtensions.html

Slide 21

Slide 21 text

• C99 • http://www.open-std.org/jtc1/sc22/wg14/www/docs/n869/ • http://www.open-std.org/JTC1/SC22/WG14/www/docs/n897.pdf • http://seclan.dll.jp/c99d/c99d00.htm • C11 • http://www.open-std.org/JTC1/SC22/WG14/www/docs/ n1570.pdf • http://port70.net/~nsz/c/ • https://gcc.gnu.org/wiki/C11Status