-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathc99features.c
89 lines (71 loc) · 1.72 KB
/
c99features.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#include <stdio.h>
#include <stdbool.h>
#include <complex.h>
#include <stdint.h>
#include <inttypes.h>
#include <sys/select.h>
// Inline functions
// Bool type
static inline bool foo()
{
printf("Bye!\n");
return true;
}
double bar()
{
return rand();
}
int main()
{
// Nice C++ style comments
int n;
scanf("%d",&n);
// Intermingled variable declaration and code
// and variable length arrays
char buf[n];
double k = bar();
// New function snprintf
snprintf(buf,n,"Hello!\n");
// Buffers not allowed to overlap! No warning but results are undefined
snprintf(buf,n, "%s some further text", buf);
printf("%s\n",buf);
// Inline function returnin bool
if (foo()) {
printf("Yes %f!\n",k);
}
//Complex numbers support
complex c=2+2i;
printf("arg=%f %d\n",carg(c));
//Portable integers
int_fast16_t my_fast_int=123;
short my_slow_short = 234;
printf("my_fast_int=%"PRIdFAST16" size=%ld\n",my_fast_int,
sizeof(my_fast_int));
printf("my_slow_short=%d size=%ld\n",my_slow_short,
sizeof(my_slow_short));
//Compound literals
struct test1 {
int a;
char b[5];
};
struct test1 t1 = {4,"abc"};
printf("%d %s\n",t1.a,t1.b);
char **str = (char *[]){"x","y","z"};
printf("%s %s %s\n",str[0],str[1],str[2]);
// New initialization mechanism
struct test1 t2 = { .b="xyz" ,.a=5 };
printf("%d %s\n",t2.a,t2.b);
// No need for temporary structs!
select(0, 0, 0, 0, & (struct timeval) { .tv_usec = 1000 });
// Also arrays
struct test1 t3[5] = {
[3] = {.a=3},
[4] = { .b = "qwe" }
};
printf("%d %s\n",t3[0].a,t3[0].b);
printf("%d %s\n",t3[3].a,t3[3].b);
printf("%d %s\n",t3[4].a,t3[4].b);
//Better Unicode support
printf("It's all \u03B5\u03BB\u03BB\u03B7\u03BD\u03B9\u03BA\u03AC to me.\n");
return 0;
}