c11

Does any C library implement C11 threads for GNU/Linux?

馋奶兔 提交于 2019-11-26 09:31:41
问题 There have been a lot of questions about C11 and C11 threading, but I don\'t see a definitive answer anywhere: Does any C library implement the C11 threading interface usable on GNU/Linux-like? e.g., provide the \"optional\" <threads.h> and the thread support library like thrd_create() , from the C11 standard near p. 376. Ideally, I\'d like to find a library that is common-ish, open-source or free, for common/generic/multi architecture (e.g., GNU/Linux, x86_64, or portable-ish). A few of the

C11 GCC threads.h not found?

徘徊边缘 提交于 2019-11-26 09:12:08
问题 The following code #include <threads.h> Gives me this error: fatal error: threads.h: No such file or directory Using the latest GCC and Clang with -std=c11. Is C11 threading not supported by GCC and Clang? Or is there a hack (or something to install) to get it? I\'m just using Ubuntu 14.04 with the gcc and clang packages from the Ubuntu repo. 回答1: The gcc document C11 status indicates that it does not support threading, it says: Threading [Optional] | Library issue (not implemented) As the

What are anonymous structs and unions useful for in C11?

核能气质少年 提交于 2019-11-26 08:13:04
C11 adds, among other things, 'Anonymous Structs and Unions'. I poked around but could not find a clear explanation of when anonymous structs and unions would be useful. I ask because I don't completely understand what they are. I get that they are structs or unions without the name afterwards, but I have always (had to?) treat that as an error so I can only conceive a use for named structs. Anonymous union inside structures are very useful in practice. Consider that you want to implement a discriminated sum type (or tagged union ), an aggregate with a boolean and either a float or a char* (i

Reading a character with scanf_s

巧了我就是萌 提交于 2019-11-26 07:49:28
问题 I was just messing around with C and ran into this small problem. As you can see from my output I getting \'╠\' this character. #include <stdio.h> int main(void) { char c; printf(\"Do you want to be X\'s or O\'s?\\n\"); scanf_s(\"%c\", &c); printf(\"You chose %c\\n\", c); } See program output 回答1: You are misusing scanf_s() . Microsoft compilers may warn you to use their secure extensions (aka c11 annex k). But, be careful if you do so. scanf_s() is not a direct replacement for scanf() . In

Operator precedence table for the C programming language

本小妞迷上赌 提交于 2019-11-26 07:49:25
问题 What would a correct operator precedence table that lists all operators in the C language look like? I have made extensive searches on the web, and found many such precedence tables. Alas, I haven\'t found a single one filling these requirements: Lists all operators in the C language as defined in ISO 9899:2011, without mixing in any C++ operators. Lists the operators in the complete and correct priority order. 回答1: Explanation Prec. denotes operator precedence , where group 1 has the highest

Does &((struct name *)NULL -> b) cause undefined behaviour in C11?

僤鯓⒐⒋嵵緔 提交于 2019-11-26 06:36:57
问题 Code sample: struct name { int a, b; }; int main() { &(((struct name *)NULL)->b); } Does this cause undefined behaviour? We could debate whether it \"dereferences null\", however C11 doesn\'t define the term \"dereference\". 6.5.3.2/4 clearly says that using * on a null pointer causes undefined behaviour; however it doesn\'t say the same for -> and also it does not define a -> b as being (*a).b ; it has separate definitions for each operator. The semantics of -> in 6.5.2.3/4 says: A postfix

Syntax and Sample Usage of _Generic in C11

百般思念 提交于 2019-11-26 04:11:35
问题 I heard C11 added generics. I\'ve googled a bit, looked at some articles, understood there\'s a new keyword ( _Generic ) and all. But I can\'t seem to grasp it all. Is it something like the generics in C# or templates in C++? Can anyone give me a brief explanation of the C11 definition of generics, its syntax and a simple sample usage example? 回答1: This is a pretty good introduction. Here's the Overview: Generic selection is implemented with a new keyword: _Generic. The syntax is similar to a

Is type-punning through a union unspecified in C99, and has it become specified in C11?

故事扮演 提交于 2019-11-25 22:35:43
问题 A number of answers for the Stack Overflow question Getting the IEEE Single-precision bits for a float suggest using a union structure for type punning (e.g.: turning the bits of a float into a uint32_t ): union { float f; uint32_t u; } un; un.f = your_float; uint32_t target = un.u; However, the value of the uint32_t member of the union appears to be unspecified according to the C99 standard (at least draft n1124), where section 6.2.6.1.7 states: When a value is stored in a member of an