c99

Is C99 support really still not widespread?

谁都会走 提交于 2019-12-10 14:47:50
问题 I was reading through some of the best practices for the GNOME project, and one thing that they kept stressing was avoiding C99 features, as support was still not widespread. Some of the things they mentioned were features like single-line comments and declaring variables in the middle of a block. It made me wonder, is C99 support, even for basic features like // comments, really still not widespread? It's been almost 15 years now since the standard was adopted, and we've even had a new

const array const {}

匆匆过客 提交于 2019-12-10 12:59:50
问题 So you can do this: void foo(const int * const pIntArray, const unsigned int size); Which says that the pointer coming is read-only and the integer's it is pointing to are read-only. You can access this inside the function like so: blah = pIntArray[0] You can also do the following declaration: void foo(const int intArray[], const unsigned int size); It is pretty much the same but you could do this: intArray = &intArray[1]; Can I write: void foo(const int const intArray[], const unsigned int

What is the “char-sequence” argument to NaN generating functions for?

≡放荡痞女 提交于 2019-12-10 12:51:37
问题 Aside from the NAN macro, C99 has two ways to generate a NaN value for a floating point number, the nanf(const char *tagp) function and strtof("NAN(char-sequence)") . Both of these methods of generating a NaN take an optional string argument (*tagp in nanf() and the char-sequence in the strtof method). What exactly does this string argument do? I haven't been able to find any concrete examples of how you'd use it. From cppreference.com we have: The call nan("string") is equivalent to the call

better understanding type promotion of variadic parameters in c

醉酒当歌 提交于 2019-12-10 12:45:47
问题 When a variable argument function is called in c the integer parameters are promoted to int and floating point parameters are promoted to double Since the prototype doesn’t specify types for optional arguments, in a call to a variadic function the default argument promotions are performed on the optional argument values. This means the objects of type char or short int (whether signed or not) are promoted to either int or unsigned int , as appropriate; and that objects of type float are

All struct identifiers are automatically forward declared

别来无恙 提交于 2019-12-10 12:34:01
问题 While answer warning: assignment from incompatible pointer type for linklist array, I noticed any undeclared identifier perceded with struct keyword are considered as forward declared identifiers. For instance the program below compiles well: /* Compile with "gcc -std=c99 -W -Wall -O2 -pedantic %" */ #include <stdio.h> struct foo { struct bar *next; /* Linked list */ }; int main(void) { struct bar *a = 0; struct baz *b = 0; struct foo c = {0}; printf("bar -> %p\n", (void *)a); printf("baz ->

long double math library implementations?

谁说胖子不能爱 提交于 2019-12-10 04:20:40
问题 What are the available portable implementations of the C99 long double math library functions ( expl , cosl , logl , etc.), if any? I've looked in fdlibm (Sun-based), NetBSD (UCB-based), etc. sources and not seen them. 回答1: You should be able to see it in the Sun-based libraries (used in pretty much all the open C libraries I am aware of, including glibc and FreeBSD one). I generally prefer BSD code for math code (more readable IMO). See here for 80-bits (Intel) long double format. For a

Forcing compiler to C99 standard

流过昼夜 提交于 2019-12-10 03:31:55
问题 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:

Is signed char overflow undefined within the range -255 to 255?

回眸只為那壹抹淺笑 提交于 2019-12-09 19:52:37
问题 Is the following code undefined behavior according to GCC in C99 mode: signed char c = CHAR_MAX; // assume CHAR_MAX < INT_MAX c = c + 1; printf("%d", c); 回答1: signed char overflow does cause undefined behavior, but that is not what happens in the posted code. With c = c + 1 , the integer promotions are performed before the addition, so c is promoted to int in the expression on the right. Since 128 is less than INT_MAX , this addition occurs without incident. Note that char is typically

Where can I find a table of all the characters for every C99 Character Set?

这一生的挚爱 提交于 2019-12-09 15:34:44
问题 I'm looking for a table (or a way to generate one) for every character in each of the following C Character Sets: Basic Character Set Basic Execution Character Set Basic Source Character Set Execution Character Set Extended Character Set Source Character Set C99 mentions all six of these under section 5.2.1 . However, I've found it extremely cryptic to read and lacking in detail. The only character sets that it clearly defines is the Basic Execution Character Set and the Basic Source

printf conversion specifier for _Bool?

拥有回忆 提交于 2019-12-09 14:31:07
问题 With printf() , I can use %hhu for unsigned char , %hi for a short int , %zu for a size_t , %tx for a ptrdiff_t , etc. What conversion format specifier do I use for a _Bool ? Does one exist in the standard? Or do I have to cast it like this: _Bool foo = 1; printf("foo: %i\n", (int)foo); 回答1: There is no specific conversion length modifier for _Bool type. _Bool is an unsigned integer type large enough to store the values 0 and 1 . You can print a _Bool this way: _Bool b = 1; printf("%d\n", b);