c11

C11 _Generic usage

て烟熏妆下的殇ゞ 提交于 2019-12-21 13:26:28
问题 I was trying to learn how to use the "new" C11 Generic expressions but I ran into a wall. Consider the following code: #include <stdlib.h> #include <stdio.h> #define test(X, Y, c) \ _Generic((X), \ double: _Generic((Y), \ double * : test_double, \ default: test_double \ ), \ int: _Generic((Y), \ int * : test_int, \ default: test_int \ ) \ ) (X, Y, c) int test_double(double a, double *b, int c); int test_int(int a, int *b, int c); int test_double(double a, double *b, int c) { return 1; } int

C11 Unicode Support

前提是你 提交于 2019-12-21 12:58:03
问题 I am writing some string conversion functions similar to atoi() or strtoll() . I wanted to include a version of my function that would accept a char16_t* or char32_t* instead of just a char* or wchar_t*. My function works fine, but as I was writing it I realized that I do not understand what char16_t or char32_t are. I know that the standard only requires that they are an integer type of at least 16 or 32 bits respectively but the implication is that they are UTF-16 or UTF-32. I also know

Compatibility of C89/C90, C99 and C11

对着背影说爱祢 提交于 2019-12-21 09:18:23
问题 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

How to use noreturn with function pointer?

ⅰ亾dé卋堺 提交于 2019-12-21 07:28:20
问题 I am writing a bootloader in C11. When the bootloader needs to transfer the control to the firmware, it reads a function pointer at a predefined memory address and calls it. The code looks like this: typedef void (FirmwareBootFn)(void); typedef struct { uint32_t stackPointer; FirmwareBootFn* programCounter; } FirmwareBootControl; static FirmwareBootControl g_bootControl __attribute__ ((section (".boot_control"))); void Firmware_boot( void ) { setStackPointer( g_bootControl.stackPointer ); g

difference between c99 and c11 [closed]

霸气de小男生 提交于 2019-12-20 08:41:04
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 3 years ago . I am learning c, presently. The book I read is C99 based. I want to update my knowledge to C11 after finishing this book, or change resource if there is a major difference. Thus, what I ask is for is an explanation or resource to update my knowledge. I only found this source.

Does C11 allow variable declarations at any place in a function?

不打扰是莪最后的温柔 提交于 2019-12-20 02:15:22
问题 Does the C11 standard (note I don't mean C++11) allow you to declare variables at any place in a function? The code below is not valid in ANSI C (C89, C90): int main() { printf("Hello world!"); int a = 5; /* Error: all variables should be declared at the beginning of the function. */ return 0; } Is it valid source code in C11? 回答1: Yes. This was already valid in C99 (see the second bullet here). 回答2: More or less. C99 introduced the ability to declare variables part way through a block and in

error: use of undeclared identifier 'errno_t'

倾然丶 夕夏残阳落幕 提交于 2019-12-18 05:47:21
问题 Here is my dead simple dummy code: #include <errno.h> int main(void) { errno_t e; return 0; } Which surprisingly raises this error: main.c:5:5: error: use of undeclared identifier 'errno_t' errno_t x; ^ I started to follow the traces : when the compiler sees the <...> inclusions it will first look at /usr/include where of course I found errno.h file. Actually it has a single line in it, besides the license comment, which is: #include <sys/errno.h> Now, at /usr/include/sys in errno.h I found

How to enable c11 on later versions of gcc?

有些话、适合烂在心里 提交于 2019-12-18 03:52:26
问题 I currently use gcc 4.6.3 . My understanding is that gcc by default uses the gnu89 standard and I would like to enable C11, the latest C standard. I tried: [pauldb@pauldb-laptop test ]$ gcc -std=c11 -o test test.c cc1: error: unrecognised command line option ‘-std=c11’ I replaced c11 with gnu11 and I get the same error. What is the correct way to enable the latest C standard for gcc? (Note: I'm interested in the latest C standard and not the latest C++ one.) 回答1: The correct option is -std

M_PI not available with gcc --std=c11 but with --std=gnu11?

核能气质少年 提交于 2019-12-18 03:32:28
问题 I noticed M_PI is unavailable on c11 . By looking at /usr/include/math.h I can see M_PI is defined if: #if !defined(__STRICT_ANSI__) || ((_XOPEN_SOURCE - 0) >= 500) ... #define M_PI 3.1415... #endif Moreover in the math.h from glibc __STRICT_ANSI__ is replaced with __USE_MISC . I am completely lost with this. What is the story in between --std=c11 and the constants defined in math.h ? Which libc should I consider on a debian distribution ? By the way, M_PI is defined in c99 and gnu11 ... 回答1:

What is the type of a bitfield?

蓝咒 提交于 2019-12-17 22:53:07
问题 I can't find anywhere in the C standard where this is specified. For example, in struct { signed int x:1; } foo; is foo.x an lvalue of type int , or something else? It seems unnatural for it to be an lvalue of type int since you cannot store any value of type int in it, only 0 or -1, but I can't find any language that would assign it a different type. Of course, used in most expressions, it would get promoted to int anyway, but the actual type makes a difference in C11 with _Generic , and I