forked from cirosantilli/cpp-cheat
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtypeof.c
More file actions
22 lines (18 loc) · 469 Bytes
/
typeof.c
File metadata and controls
22 lines (18 loc) · 469 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
/* # typeof
*
* Like C++11 decltype.
*
* Partially reproductible with C11 `_Generic`.
*
* https://stackoverflow.com/questions/6513806/would-it-be-possible-to-add-type-inference-to-the-c-language/31709221#31709221
*/
#include "common.h"
int main(void) {
/* Same as: double j = 0.5; */
typeof(1 + 0.5) j = 0.5;
assert(j == 0.5);
/* Similar to C++ auto. */
__auto_type k = 0.5;
assert(sizeof(j) == sizeof(k));
return EXIT_SUCCESS;
}