c99

Why does C99 complain about storage sizes?

为君一笑 提交于 2019-11-26 16:53:58
问题 This is some code I'm compiling on Linux: #include <net/if.h> int main() { struct ifreq ifr; } gcc test.c is fine. gcc -std=gnu99 test.c is fine. gcc -std=c99 test.c fails with the following error: test.c: In function ‘main’: test.c:4:16: error: storage size of ‘ifr’ isn’t known What's different about C99 that it doesn't like the definition of struct ifreq in Linux? 回答1: It's a chain of consequences of preprocessing and GNU C vs C99. First up, net/if.h : net/if.h includes features.h Later on,

Does either ANSI C or ISO C specify what -5 % 10 should be?

那年仲夏 提交于 2019-11-26 16:34:42
I seem to remember that ANSI C didn't specify what value should be returned when either operand of a modulo operator is negative (just that it should be consistent). Did it get specified later, or was it always specified and I am remembering incorrectly? C89, not totally (§3.3.5/6). It can be either -5 or 5, because -5 / 10 can return 0 or -1 ( % is defined in terms of a linear equation involving / , * and + ): When integers are divided and the division is inexact, if both operands are positive the result of the / operator is the largest integer less than the algebraic quotient and the result

Is it a good idea to use C99 VLA compared to malloc/free?

↘锁芯ラ 提交于 2019-11-26 16:26:14
问题 Is it a good idea to use C99 VLA? When is it appropriate to use VLA compared to malloc/free? (since VLA may blow up stack?) 回答1: Yes, except in cases where you know your stack can blow up. You can also change the size of the stack if necessary, it's different how on every OS but it's possible. The advantages of VLA are: Fast : adjusting the stack pointer and/or the frame pointer would have been done anyway so the cost of a VLA is nearly 0. Easy : a simple definition, no pointer to initialize,

Is there a document describing how Clang handles excess floating-point precision?

丶灬走出姿态 提交于 2019-11-26 16:10:51
问题 It is nearly impossible(*) to provide strict IEEE 754 semantics at reasonable cost when the only floating-point instructions one is allowed to used are the 387 ones. It is particularly hard when one wishes to keep the FPU working on the full 64-bit significand so that the long double type is available for extended precision. The usual “solution” is to do intermediate computations at the only available precision, and to convert to the lower precision at more or less well-defined occasions.

How to tell GCC that a pointer argument is always double-word-aligned?

久未见 提交于 2019-11-26 15:54:33
问题 In my program I have a function that does a simple vector addition c[0:15] = a[0:15] + b[0:15] . The function prototype is: void vecadd(float * restrict a, float * restrict b, float * restrict c); On our 32-bit embedded architecture there is a load/store option of loading/storing double words, like: r16 = 0x4000 ; strd r0,[r16] ; stores r0 in [0x4000] and r1 in [0x4004] The GCC optimizer recognizes the vector nature of the loop and generates two branches of the code - one for the case where

Realistic usage of the C99 &#39;restrict&#39; keyword?

吃可爱长大的小学妹 提交于 2019-11-26 15:01:33
问题 I was browsing through some documentation and questions/answers and saw it mentioned. I read a brief description, stating that it would be basically a promise from the programmer that the pointer won't be used to point somewhere else. Can anyone offer some realistic cases where its worth actually using this? 回答1: restrict says that the pointer is the only thing that accesses the underlying object. It eliminates the potential for pointer aliasing, enabling better optimization by the compiler.

Setting alias for GCC in Windows PowerShell

家住魔仙堡 提交于 2019-11-26 14:51:57
问题 I'm trying to set up a "gcc99" alias in Windows PowerShell which is equal to "gcc -std=C99 -pedantic -Wall". The idea is to use fewer keystrokes to ensure that GCC is running in c99 mode. (I've tried my best to adapt the guidelines in the following post to Windows PowerShell: Setting std=c99 flag in GCC ) When I try to compile after setting up such an alias (exhibit 1 below), I receive an error. As reference, I don't receive this error if I use the extended command to compile (exhibit 2 below

Get warning when a variable is shadowed

一笑奈何 提交于 2019-11-26 14:36:15
问题 I generally want to avoid code like this: #include <stdio.h> int main(int argc, char *argv[]){ int n = 3; for (int n = 1; n <= 10; n++){ printf("%d\n", n); } printf("%d\n", n); } How can I find such usage of variables? That means, that in the same function a "more local" variable has the same name as a more global variable? C-Standard : C 99 回答1: Both gcc and clang support the -Wshadow flag which will warn about variables that shadow one another. For example the warning I receive from gcc for

C99 inline function in .c file

两盒软妹~` 提交于 2019-11-26 14:33:28
I defined my function in .c (without header declaration) as here: inline int func(int i) { return i+1; } Then in the same file below I use it: ... i = func(i); And during the linking I got "undefined reference to 'func'". Why? The inline model in C99 is a bit different than most people think, and in particular different from the one used by C++ inline is only a hint such that the compiler doesn't complain about doubly defined symbols. It doesn't guarantee that a function is inlined, nor actually that a symbol is generated, if it is needed. To force the generation of a symbol you'd have to add

C99 boolean data type?

末鹿安然 提交于 2019-11-26 14:31:14
What's the C99 boolean data type and how to use it? Include <stdbool.h> header #include <stdbool.h> int main(void){ bool b = false; } Macros true and false expand to 1 and 0 respectively. Section 7.16 Boolean type and values < stdbool.h > 1 The header <stdbool.h> defines four macros. 2 The macro bool expands to _Bool. 3 The remaining three macros are suitable for use in #if preprocessing directives. They are true : which expands to the integer constant 1, false: which expands to the integer constant 0, and __bool_true_false_are_defined which expands to the integer constant 1. 4 Notwithstanding