c99

ftell at a position past 2GB

送分小仙女□ 提交于 2019-11-27 15:34:25
On a 32-bit system, what does ftell return if the current position indicator of a file opened in binary mode is past the 2GB point? In the C99 standard, is this undefined behavior since ftell must return a long int (maximum value being 2**31-1 )? Ahmed Masud on long int long int is supposed to be AT LEAST 32-bits, but C99 standard does NOT limit it to 32-bit. C99 standard does provide convenience types like int16_t & int32_t etc that map to correct bit sizes for a target platform. on ftell/fseek ftell() and fseek() are limited to 32 bits (including sign bit) on the vast majority of 32-bit

Compiler support of GNU Statement Expression

六眼飞鱼酱① 提交于 2019-11-27 15:27:06
Which modern compilers support the Gnu Statement expression (C and C++ languages). What versions should I have to use a statement expressions? Statement expression is smth like ({ code; code; retval }) : int b=56; int c= ({int a; a=sin(b); a}) I already know some such compilers: GCC >=3 Clang/LLVM >= ? Intel C++ Compiler >= 6.0 (Linux version, check page 4 ; bit limited ) Sun Studio >= 12 ( New Language Extensions ) IBM XL for z/OS ( marked as IBM extension ) Open64 (as it uses osprey-gcc frontend) This compiler seems not to support this (i'm unsure): MS Visual C++ PS. some C/C++ compilers are

C99 complex support with visual studio

天涯浪子 提交于 2019-11-27 15:14:42
I would like to use complex numbers as defined in C99, but I need to support compilers which do not support it (MS compilers come to mind). I don't need many functions, and implementing the needed functions on compilers without support is not too difficult. But I have a hard time implementing the 'type' itself. Ideally, I would like to do something like: #ifndef HAVE_CREAL double creal(complex z) { /* .... */ } #endif #ifndef HAVE_CREALF float creal(float complex z) { /* ... */ } #endif But I am not sure I see how to do this if the compiler cannot recognize 'float complex'. I would actually

Why does C99 complain about storage sizes?

泄露秘密 提交于 2019-11-27 14:45:24
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? 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, it defines struct ifreq inside a #ifdef __USE_MISC block. So: What is __USE_MISC ? -- it is stuff common to

Why can't gcc find the random() interface when -std=c99 is set?

不想你离开。 提交于 2019-11-27 14:38:19
问题 I do "#include <stdlib.h>" at the top of the source. Example compilation: /usr/bin/colorgcc -std=c99 -fgnu89-inline -g -Wall -I/usr/include -I./ -I../ -I../../ -I../../../ -I../../../../ -O3 -o f8 f8.c In file included from f8.c:7: ctype-cmp.c: In function ‘randomized’: ctype-cmp.c:48: warning: implicit declaration of function ‘random’ ctype-cmp.c: In function ‘main’: ctype-cmp.c:153: warning: implicit declaration of function ‘srandom’ ais@xcalibur:t$ When I turn off -std=c99, the function

Why is int x[n] wrong where n is a const value?

ⅰ亾dé卋堺 提交于 2019-11-27 14:20:26
问题 I cannot understand why doing this is wrong: const int n = 5; int x[n] = { 1,1,3,4,5 }; even though n is already a const value. While doing this seems to be right for the GNU compiler: const int n = 5; int x[n]; /*without initialization*/ I'm aware of VLA feature of C99 and I think it's related to what's going on but I just need some clarification of what's happening in the background. 回答1: The key thing to remember is that const and "constant" mean two quite different things. The const

How to compile a C project in C99 mode?

☆樱花仙子☆ 提交于 2019-11-27 13:39:03
问题 I got the following error message while compiling the C code: error: 'for' loop initial declarations are only allowed in C99 mode note: use option -std=c99 or -std=gnu99 to compile your code What does it mean? How to fix it? 回答1: You have done this: for (int i=0;i<10;i++) { And you need to change it to this: int i; for (i=0;i<10;i++) { Or, as the error says, use option -std=c99 or -std=gnu99 to compile your code. Update copied from Ryan Fox's answer : gcc -std=c99 foo.c -o foo Or, if you're

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

自作多情 提交于 2019-11-27 13:37:35
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?) 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, to check to free and no risk of memory leaks. It's automatically thread safe as each thread has its own

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

白昼怎懂夜的黑 提交于 2019-11-27 12:59:42
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. Recent versions of GCC handle excess precision in intermediate computations according to the

How does the compiler allocate memory without knowing the size at compile time?

回眸只為那壹抹淺笑 提交于 2019-11-27 11:24:52
问题 I wrote a C program that accepts integer input from the user, that is used as the size of an integer array, and using that value it declares an array of given size, and I am confirming it by checking the size of the array. Code: #include <stdio.h> int main(int argc, char const *argv[]) { int n; scanf("%d",&n); int k[n]; printf("%ld",sizeof(k)); return 0; } and surprisingly it is correct! The program is able to create the array of required size. But all static memory allocation is done at