c99

About cast in integer constant expression (in standard C)

自闭症网瘾萝莉.ら 提交于 2019-12-21 04:11:07
问题 In standard C (I mean C99 or C11) we have the so-called integer constant expressions , which are constant expressions whose operands are all constant integers. There are other constraints, as to avoid comma operators in the expression. However, other non-integer objects (even non-constant) are allowed in some special cases. For example, if the sizeof operator is applied to an object whose size is known in translation time, this is allowed as part of an integer constant expression (note that

Is “*p = ++(*q)” undefined when p and q point to the same object?

℡╲_俬逩灬. 提交于 2019-12-21 03:42:38
问题 after reading about sequence points, I learned that i = ++i is undefined. So how about this code: int i; int *p = &i; int *q = &i; *p = ++(*q); // that should also be undefined right? Let's say if initialization of p and q depends on some (complicated) condition. And they may be pointing to same object like in above case. What will happen? If it is undefined, what tools can we use to detect? Edit: If two pointers are not supposed to point to same object, can we use C99 restrict? Is it what

What can human beings make out of the restrict qualifier?

流过昼夜 提交于 2019-12-20 10:29:15
问题 If I got the C99 restrict keyword right, qualifying a pointer with it is a promise made that the data it references won't be modified behind the compiler's back through aliasing. By contrast, the way I understand the const qualifier is as compiler-enforced documentation that a given object won't be modified behind the back of a human being writing code. The compiler might get a hint as a side effect, but as a programmer I don't really care. In a similar way, would it be appropriate to

What's the C++ equivalent of UINT32_MAX?

狂风中的少年 提交于 2019-12-20 10:22:25
问题 In C99, I include stdint.h and that gives me UINT32_MAX as well as uint32_t. However, in C++ the UINT32_MAX gets defined out. I can define __STDC_LIMIT_MACROS before including stdint.h, but this doesn't work if someone is including my header after already including stdint.h themselves. So in C++, what's the standard way of finding out the maximum value representable in a uint32_t? 回答1: Well, I don't know about uint32_t but for the fundamental types ( bool, char, signed char, unsigned char,

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.

Compiling c code with bool without using c99 standard

帅比萌擦擦* 提交于 2019-12-20 07:18:05
问题 I've tried to compile a code using a bool variable in C and I've included the stdbool header but when I compiled it I didn't specify that I want to compile it with the c99 standard (so it was compiled with ANSI C standard) but it worked anyway. I was wondering why is that ? Here's the code : #include <stdio.h> #include <stdbool.h> int main() { char name[20]; printf("What's your name ? "); gets(name); printf("Nice to meet you %s.\n", name); bool exit = false; char c; printf("Do you wish to

Freeing global variable

元气小坏坏 提交于 2019-12-20 06:15:10
问题 Suppose I have a global variable that contains a large structure: typedef struct { char Big[1024] } LARGE; static LARGE x; void main() { free(x); } Can I safely call free(x) from main when I dont need it anymore? 回答1: No. You didn't dynamically allocate x so don't need to (and cannot) free it. If you absolutely need to free the memory before your program exits, declare a pointer as global, allocate it on demand, using malloc or calloc , then free it when you're finished with the structure.

Are “Statement and Declarations in Expressions” specific to GNU C?

时光总嘲笑我的痴心妄想 提交于 2019-12-20 04:16:21
问题 Are Statement and Declarations in Expressions specific to GNU C ? Or this feature is also included in C99 standard ? 回答1: It's a GCC extension. (See the GCC docs, e.g. here for gcc 4.3.3, for a full list of GCC extensions; and the C99 spec is available here.) GCC will warn about such things if you use the -pedantic -std=c99 flags, e.g.: $ cat foo.c int main(void) { return ({ int a = 0; a; }); } $ gcc -pedantic -std=c99 -c foo.c foo.c: In function 'main': foo.c:3: warning: ISO C forbids braced

got compile error when use clock_gettime in c99

两盒软妹~` 提交于 2019-12-19 16:13:55
问题 when I use clock_gettime in my code snippet, and compile with flag -std=c99, I got a error like this: warning: implicit declaration of function 'clock_gettime' error: 'CLOCK_REALTIME' undeclared (first use in this function) and I have included the file 'time.h'. anyone knows how to fix it. 回答1: in your original code with -std=c99, try adding #define _POSIX_C_SOURCE >= 199309L the man page for clock_gettime indicates this is a necessary feature test macro requirement. 来源: https://stackoverflow

C fixed size array treated as variable size

寵の児 提交于 2019-12-19 14:05:12
问题 I have been trying to define a static array with size that should be known at compile time (it's a constant expression). It appears that gcc cannot determine the size of the array when it contains a floating point constant (and I get "storage size of ... isn’t constant"). Here is a minimal example: int main(void) { static int foo[(unsigned)(2 / 0.5)]; return 0; } What is the reason for this behavior? EDIT I already have the answer I needed. I still don't understand the rationale behind not