File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ _Static_assert (__STDC_VERSION__ > 201100 , "" );
2+
3+ /**
4+ https://gcc.gnu.org/wiki/C11Status
5+
6+ */
7+ #include <stdnoreturn.h>
8+ #include <stdatomic.h>
9+ #include <math.h>
10+ #include <assert.h>
11+ #include <stdio.h>
12+
13+ #if !__STDC_NO_THREADS__
14+ #include <threads.h>
15+
16+ /**
17+
18+ https://en.cppreference.com/w/c/thread
19+
20+ https://www.gnu.org/software/libc/manual/html_node/ISO-C-Threads.html
21+ */
22+
23+ int run (void * arg )
24+ {
25+ * (int * )arg = 1 ;
26+ }
27+
28+ int thrd_passed ;
29+
30+ _Static_assert (thrd_success == 0 , "" );
31+
32+ void thrd_test ()
33+ {
34+ thrd_t thread ;
35+ int res ;
36+ int passed = 0 ;
37+ res = thrd_create (& thread , run , & passed );
38+ assert (!res );
39+ assert (res == thrd_success );
40+
41+ thrd_join (thread , NULL );
42+ assert (passed );
43+ }
44+
45+ #else
46+
47+ #pragma message "thrd_test skipped"
48+ void thrd_test ()
49+ {
50+ }
51+
52+ #endif
53+
54+ #define cbrt (x ) _Generic((x), long double: cbrtl, \
55+ default: cbrt, \
56+ float: cbrtf)(x)
57+
58+ int main ()
59+ {
60+ assert (__STDC_VERSION__ > 201100 );
61+ atomic_int acnt ;
62+ ++ acnt ; // is thread safe
63+ assert (cbrt (1.1 * 1.1 * 1.1 ) == 1.1 );
64+ assert (cbrt (8 ) == 2 );
65+ thrd_test ();
66+ return 0 ;
67+ }
Original file line number Diff line number Diff line change 1- all : tr ansi 99 libc
1+ all : tr ansi 99 libc 11
22
33CFLAGS+ =-Wpedantic
44CFLAGS+ =-Wextra -Wno-missing-field-initializers
55
66tr : CFLAGS+=-std=c89 -Wtraditional
77ansi : CFLAGS+=-ansi
8899 : CFLAGS+=-std=c99
9+ 11 : CFLAGS+=-std=c11
10+ 11 : CC=musl-gcc
11+
912check :
1013 ./tr
1114 ./ansi
1215 ./99
1316 ./libc
17+ ./11
1418 @echo $@ finished
Original file line number Diff line number Diff line change 11# C features examples by standard version
2- * [ Legacy "Traditional"] ( tr.c )
3- * [ ANSI C / C89] ( ansi.c )
4- * [ C99] ( 99.c )
2+ * [ C11, ISO 9899:2011] ( 11.c )
53* [ libc example] ( libc.c )
4+ * [ C99, ISO 9899:1999] ( 99.c )
5+ * [ ANSI C / C89, ISO 9899:199409] ( ansi.c )
6+ * [ Legacy "Traditional"] ( tr.c )
67
78References
89* [ Language Standards Supported by GCC] ( https://gcc.gnu.org/onlinedocs/gcc/Standards.html )
You can’t perform that action at this time.
0 commit comments