c11

__STDC_LIB_EXT1__ availability in gcc and clang

别等时光非礼了梦想. 提交于 2019-12-05 07:52:48
Since a quick Google search did not find anything, I will try to ask here (since many people involved in gcc/clang hang around here) - What is the status of __STDC_LIB_EXT1__ in gcc/clang? We are developing a cross platform applicataion and I wanted to use some of the safe bounds checking functions from <stdio.h> (which by miracle are available on Visual Studio 2017), but could not compile the code with Xcode 9.2. I assumed maybe the clang version Xcode uses is outdated, but gcc 6.3.0 on Ubuntu behaves the same. I am trying to use tmpnam_s with the following sample: #if defined(__STDC_LIB_EXT1

Are there any implementations that support a negative zero, or reserve it as a trap representation?

纵然是瞬间 提交于 2019-12-05 06:08:40
问题 On most implementations of this day and age, a signed integer value that has a bit pattern of 1 for the sign bit and all 0 for the value bits tends to represent the lowest possible value for that signed integer type. However, as 6.2.6.2p2 states, that's not a requirement: Which of these applies is implementation-defined, as is whether the value with sign bit 1 and all value bits zero (for the first two), or with sign bit and all value bits 1 (for ones' complement), is a trap representation or

Is it legal to access struct members via offset pointers from other struct members?

我们两清 提交于 2019-12-05 06:01:17
In these two examples, does accessing members of the struct by offsetting pointers from other members result in Undefined / Unspecified / Implementation Defined Behavior? struct { int a; int b; } foo1 = {0, 0}; (&foo1.a)[1] = 1; printf("%d", foo1.b); struct { int arr[1]; int b; } foo2 = {{0}, 0}; foo2.arr[1] = 1; printf("%d", foo2.b); Paragraph 14 of C11 § 6.7.2.1 seems to indicate that this should be implementation-defined: Each non-bit-field member of a structure or union object is aligned in an implementation-defined manner appropriate to its type. and later goes on to say: There may be

Why doesn't C11 support lambda functions

假如想象 提交于 2019-12-05 05:45:19
The new C++11 standard supports lambda functions, which I think is a useful feature. I understand that the C and C++ standards differ from each other but I don't understand why C11 doesn't support lambda functions. I think it could have a lot of use. Is there a reason why the developers of the C11 standard choose not to include this feature? This is really just my opinion, since I don't know what the committee thinks. On the one hand, Lisp has been supporting lambda expression since its birth, which is in 1958. The C programming language was born in 1972. So lambda expression actually has a

Compatibility of C89/C90, C99 and C11

本秂侑毒 提交于 2019-12-05 03:41:54
I just read: C Wikipedia entry . As far as I know there are 3 different versions of C that are widely used: C89, C99 and C11. My question concerns the compatibility of source code of different versions. Suppose I am going to write a program (in C11 since it is the latest version) and import a library written in C89. Are these two versions going to work together properly when compiling all files according to the C11 specification? Question 1 : Are the newer versions of C i.e. C99, C11 supersets of older C versions? By superset I mean, that old code will compile without errors and the same

Forcing compiler to C99 standard

江枫思渺然 提交于 2019-12-05 02:57:12
I was coding on my project when I discovered that the anonymous structs I've been using for a while are actually only available in C11, not C99, the standard I want to code against. Given the following code: struct data { int a; struct { int b; int c; }; }; int main() { struct data d; d.a = 0; d.b = 1; d.c = 2; return 0; } This code should only compile in C11 (or if compiler extensions provide this feature and are enabled). So let's see the results on different compilers: clang 5 compiler: Apple LLVM version 5.0 (clang-500.2.79) (based on LLVM 3.3svn) Target: x86_64-apple-darwin13.1.0 Thread

Does realloc of memory allocated by C11 aligned_alloc keep the alignment?

自作多情 提交于 2019-12-05 02:53:45
Consider the following (C11) code: void *ptr = aligned_alloc(4096, 4096); ... // do something with 'ptr' ptr = realloc(ptr, 6000); Since the memory that ptr points to has a 4096-byte alignment from aligned_alloc , will it (read: is it guaranteed to) keep that alignment after a (successful) call to realloc ? Or could the memory revert to the default alignment? The alignment is not kept with the pointer. When you call realloc you can only rely on the alignment that realloc guarantees. You'll need to use aligned_alloc to perform any reallocations. 来源: https://stackoverflow.com/questions/20314602

Do unnamed bit-fields have well-defined semantics?

血红的双手。 提交于 2019-12-05 02:14:34
Is the following code guaranteed to terminate normally and successfully? #include <assert.h> struct foo_s { union { struct { unsigned a : 10; unsigned : 6; }; struct { unsigned : 10; unsigned b : 6; }; struct { unsigned : 10; unsigned c : 6; }; }; }; int main () { struct foo_s f; f.a = 0; f.b = 1; assert(f.a == 0); return 0; } While answering a different question , the possibility was raised that assignment to a named bit-field in a structure that also contains an unnamed bit-field may cause arbitrary data to be written to those bits. C.11 §6.7.2.1 ¶12 states: A bit-field declaration with no

Why is there no ASCII or UTF-8 character literal in C11 or C++11?

流过昼夜 提交于 2019-12-04 22:47:45
Why is there no UTF-8 character literal in C11 or C++11 even though there are UTF-8 string literals? I understand that, generally-speaking, a character literal represents a single ASCII character which is identical to a single-octet UTF-8 code point, but neither C nor C++ says the encoding has to be ASCII. Basically, if I read the standard right, there's no guarantee that '0' will represent the integer 0x30, yet u8"0" must represent the char sequence 0x30 0x00. EDIT: I'm aware not every UTF-8 code point would fit in a char. Such a literal would only be useful for single-octet code points (aka,

C11 type-generic expressions - why not just add function overloading?

依然范特西╮ 提交于 2019-12-04 22:26:43
I was just reading the Wikipedia article on C11 , the new version of the C standard released in Dec 2011, and I saw that one of the added features was "type-generic expressions": Type-generic expressions using the _Generic keyword. For example, the following macro cbrt(x) translates to cbrtl(x) , cbrt(x) or cbrtf(x) depending on the type of x : #define cbrt(X) _Generic((X), long double: cbrtl, \ default: cbrt, \ float: cbrtf)(X) This looks pretty horrible to me - if they are going to change the language anyways, why not just add function overloading like in C++? Potatoswatter C has one