c11

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

不羁的心 提交于 2020-01-02 01:31:05
问题 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? 回答1: The alignment is not kept with the pointer. When you call realloc you can only rely on the alignment that realloc guarantees. You

Does C99/C11 restrict type qualifier imply anything for functions without definition?

本小妞迷上赌 提交于 2020-01-01 13:15:58
问题 Suppose we have a function declaration for which we do not have access to its definition: void f(int * restrict p, int * restrict q, int * restrict r); Since we do not know how the pointers will be accessed, we cannot know if a call will trigger undefined behavior or not -- even if we are passing the same pointer, like the example at 6.7.3.1.10 explains: The function parameter declarations: void h(int n, int * restrict p, int * restrict q, int * restrict r) { int i; for (i = 0; i < n; i++) p

What is a composite type in C?

限于喜欢 提交于 2019-12-31 21:42:12
问题 From §6.2.7.5 (page 66): EXAMPLE Given the following two file scope declarations: int f(int (*)(), double (*)[3]); int f(int (*)(char *), double (*)[]); The resulting composite type for the function is: int f(int (*)(char *), double (*)[3]); Above the example, they explain that a composite type is a type, compatible with two different types. I would intuitively understand the phrase "composite type" as meaning "structures and unions", which appears to be way off-target. What is a composite

Does each branch of c11 _Generic generic association's result expressions have to be valid?

喜你入骨 提交于 2019-12-31 03:24:30
问题 I can't seem to pass the arguments to functions expecting different arguments (or to other _Generic macros which implement a subset of the types of the first one). #define DEBUG_PRINT(x,...) _Generic((x), \ debug_print_options *: DEBUG_PRINT_CUSTOM_TYPE(x, __VA_ARGS__), \ default: DEBUG_PRINT_BASIC_TYPE(x, __VA_ARGS__)) #define DEBUG_PRINT_BASIC_TYPE(x,...) debug_print_printf_specifier((#x), (x), TYPE_TO_PRINTF_SPECIFIER(x), __FILE__, __LINE__, _my_func__, &((struct debug_print_options){__VA

How to declare a variable as thread local portably?

雨燕双飞 提交于 2019-12-30 04:11:07
问题 C11 introduces the _Thread_local storage class specifier that can be used in combination with the static and extern storage class specifiers to declare a variable as thread local. The GNU C compiler suite implements a storage class specifier __thread with the same same semantics. Unfortunately I did not find any compiler (I tried gcc, clang and SUN studio) that actually implements the _Thread_local keywords. I currently use the following construct to declare a keyword thread_local : /* gcc

What is C11 cor 1:2012?

雨燕双飞 提交于 2019-12-29 06:43:26
问题 I just noticed that there has been a correction to the C11 standard called ISO/IEC 9899:2011/Cor 1:2012 . What was changed in this update? 回答1: This technical corrigendum is available free of charge as pdf, from ISO or from your national standard institute. For convenience, I will cite it as whole here, since there are just two changes: Page 176, 6.10.8.1 Replace: __STDC_VERSION__ The integer constant 201ymmL. 178) with: __STDC_VERSION__ The integer constant 201112L. 178) Page 177, 6.10.8.3

What is the __STDC_VERSION__ value for C11?

ⅰ亾dé卋堺 提交于 2019-12-28 13:42:06
问题 I know that compilers use __STDC__ to indicate that a compiler is standard C and, from, there, you can use __STDC_VERSION__ to figure out which level of the standard you're using. I also know that C90 had no value, C90 amendment 1 had 199401L and C99 had 199901L . The latest C1x draft I have simply states it as 201ymmL and I'm assuming it was made a less "vague" value in the final standard. My guess is that it will be 201112L since that's when C11 was ratified but I'd like to be certain. I

Is there a meaningful distinction between freestanding and hosted implementations?

≡放荡痞女 提交于 2019-12-28 02:13:08
问题 The question I have is mostly related to section four, paragraph six. The two forms of conforming implementation are hosted and freestanding. A conforming hosted implementation shall accept any strictly conforming program. As I understand, this constitutes the typical application environment, with filesystems, allocated memory and threads... A conforming freestanding implementation shall accept any strictly conforming program in which the use of the features specified in the library clause

Adjacent character and string literal tokens

牧云@^-^@ 提交于 2019-12-24 16:28:27
问题 It's a familiar fact that in C you can write "a" "b" and get "ab" . This is discussed in the C11 standard: In translation phase 6, the multibyte character sequences specified by any sequence of adjacent character and identically-prefixed string literal tokens are concatenated into a single multibyte character sequence. The phrase "character and..." would seem to suggest you can get the same results by writing 'a' "b" , but I've never come across that usage and GCC and the Microsoft compiler

Are conformant array parameters VLAs?

江枫思渺然 提交于 2019-12-24 10:39:41
问题 CERT's Secure Coding Standard includes an item (API05-C) which encourages the use of conformant array parameters, which is a recommendation I've implemented in a lot of my code (hidden behind a macro for compilers which don't support them). For those who don't know, a conformant array parameter is something like: void foo(int length, char data[length]); API05-C provides more information. Lots of compilers don't like variable-length arrays (for good reason). C11 demotes them from required (as