c11

char16_t and char32_t endianness

大兔子大兔子 提交于 2019-12-13 16:43:21
问题 In C11, support for portable wide char types char16_t and char32_t are added for UTF-16 and UTF-32 respectively. However, in the technical report, there is no mention of endianness for these two types. For example, the following snippet in gcc-4.8.4 on my x86_64 computer when compiled with -std=c11 : #include <stdio.h> #include <uchar.h> char16_t utf16_str[] = u"十六"; // U+5341 U+516D unsigned char *chars = (unsigned char *) utf16_str; printf("Bytes: %X %X %X %X\n", chars[0], chars[1], chars[2

sizeof applied to array types

江枫思渺然 提交于 2019-12-13 15:12:48
问题 The c11 standard says that sizeof, "when applied to an operand that has array type, the result is the total number of bytes in the array" (6.5.3.4, bullet 4). The foot note (103) says: "When applied to a parameter declared to have array or function type, the sizeof operator yields the size of the adjusted (pointer) type". I take from this that when applied to an array type, sizeof gives the size of the array (number of elements x size of elements), but applied to parameters declared to have

Is (x++, y) + (y++, x) undefined or unspecified, and if unspecified, what can it compute?

三世轮回 提交于 2019-12-13 02:35:19
问题 The comma sequence operator introduces a sequence point in an expression. I am wondering whether this means that the program below avoids undefined behavior. int x, y; int main() { return (x++, y) + (y++, x); } If it does avoid undefined behavior, it could still be unspecified, that is, return one of several possible values. I would think that in C99, it can only compute 1 , but actually, various versions of GCC compile this program into an executable that returns 2 . Clang generates an

How to compile with c11 standard library on OS X with clang?

折月煮酒 提交于 2019-12-13 01:33:17
问题 Hey I am trying to compile c code that uses functions from the c11 standard library on OS X with clang. The compiler option -std=c11 allows me to use c11 language features. But when I am using new functions like at_quick_exit I get the following warning implicit declaration of function 'at_quick_exit' is invalid in C99 . The source code has the following line #include <stdlib.h> The clang option -stdlib does not help. My Systems: OS X Yosemite 10.10.3 $ clang -v Apple LLVM version 6.1.0

c11 _Generic adding types

两盒软妹~` 提交于 2019-12-12 16:20:43
问题 How do you add extra types to c11 _Generic Functions? Do you have to #undef/re-#define it?(if so would the following work) or is there a nicer way? #define to_str(X) _Generic((X), \ long double: ld_str, \ double: d_str, \ float: f_str, \ )(X) #undef to_str #define to_str(X) _Generic((X), \ long double: ld_str, \ double: d_str, \ float: f_str, \ int: i_str, \ )(X) 回答1: I am not sure that I understand your question completely. You mean that you have a type generic macro that is given by some

Does an available compiler provide an implementation of the C11 '_Atomic' keyword and its related header 'stdatomic.h'?

一个人想着一个人 提交于 2019-12-12 12:09:42
问题 I know the C11 standard is only a month old, but the drafts for _Atomic are much older. I also know the GCC compiler makes a serious effort implementing such features in advance of the standard becoming officially approved. but even there the support is not yet ready for prime-time. However, I'd be interested in other compilers as well: Visual Studio, or embedded compilers cq. environments. Is anyone compiler provider gearing up to provide such support? Any links are welcome. I'm asking,

clang c11 threads.h not found

。_饼干妹妹 提交于 2019-12-12 08:27:04
问题 I am trying to setup a c11 thread example in xcode... but it doesn't seem to have the threads.h header, though it isn't complaning about the macro described here: http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1570.pdf __STDC_NO_THREADS__The integer constant 1, intended to indicate that the implementation does not support the <threads.h> header. 回答1: Looks like almost nothing supports the threads feature in C11... maybe I will try to get it into clang... 回答2: With the clang on my machine (v

Lifetime of temporary objects in C11 vs C99

╄→尐↘猪︶ㄣ 提交于 2019-12-12 07:45:33
问题 I am trying to decipher a note that led to a change between C99 and C11. The change proposed in that note ended up in C11's 6.2.4:8, namely: A non-lvalue expression with structure or union type, where the structure or union contains a member with array type (including, recursively, members of all contained structures and unions) refers to an object with automatic storage duration and temporary lifetime. Its lifetime begins when the expression is evaluated and its initial value is the value of

Memory position of elements in C/C++ union

眉间皱痕 提交于 2019-12-12 07:13:09
问题 I have a union in C like this: union AUnion { struct CharBuf { char *buf; size_t len; } charbuf; uint8_t num; double fp_num; }; My question is, can I guarantee that if given the following: union AUnion u; Then the following are true: &u == &u.num &u == &u.fp_num &u == &u.charbuf I.e they all start at the beginning of the memory segment where u is stored. In the case of this C program compiled with gcc version 5.3.0 and -std=c11 the above is true: #include <stdio.h> #include <stdint.h>

_Static_assert replacement to show value in C

落花浮王杯 提交于 2019-12-11 17:08:36
问题 Is it possible to have the compiler error/warning diagnostic output a compile-time computed numeric value in C11 or C17 (i.e. not using templates)? The below link does this in C++ using template magic. The intention is to use this as a _Static_assert replacement which prints the values of the non-equal failed expression. Ideally, it should be able to evaluate the expression as true or false, and print only when it fails evaluation. This is obviously compiler-dependent, so assume GCC. Display