c99

Why does sizeof(x)++ compile? [duplicate]

做~自己de王妃 提交于 2020-05-14 14:38:03
问题 This question already has answers here : Why does sizeof(x++) not increment x? (9 answers) Closed 6 days ago . I have run into the following code snippet: int a = 3; printf("%d", sizeof(a)++); Apparently this will compile with GCC 9.3.0 and -std=c99. While this does not compile: printf("%d", sizeof(3)++); GCC prints an error error: lvalue required as increment operand Before I have compiled the first snippet I would have expected such an error. The operand of the postfix ++ operator shall be

Why does sizeof(x)++ compile? [duplicate]

随声附和 提交于 2020-05-14 14:37:24
问题 This question already has answers here : Why does sizeof(x++) not increment x? (9 answers) Closed 6 days ago . I have run into the following code snippet: int a = 3; printf("%d", sizeof(a)++); Apparently this will compile with GCC 9.3.0 and -std=c99. While this does not compile: printf("%d", sizeof(3)++); GCC prints an error error: lvalue required as increment operand Before I have compiled the first snippet I would have expected such an error. The operand of the postfix ++ operator shall be

why segmentation fault error in recursive function

会有一股神秘感。 提交于 2020-03-26 03:51:27
问题 Hi I wrote this code and the aim is to see weather a word is palyndrom or not, I get a segmenation fault while executing, may you help? Is it a good way to see if a word is palyndrom? thx in advance #include <stdio.h> #include <stdlib.h> #include <string.h> int m=1; void palindromi(); int main (int argc, char *argv[]) { int len, a, i=0; if (argc != 2) exit(0); len = strlen(argv[1]); a = len-1; printf("La lunghezza della parola e' %d\n",len); palindromi(argv[1], len, a, i); return 0; } void

Name spaces in C

我的梦境 提交于 2020-03-21 08:39:37
问题 I have the following code: typedef struct Y {int X;} X; enum E {X}; which generates a error: error: 'X' redeclared as different kind of symbol As I know, C has implicitly defined namespaces for structure, union, and enum tags and also for their members. So, I'm not sure why does E::X collide with typedef structure tag X ? What exactly are name spaces in C? 回答1: C does not have a separate namespace for enum members. When you write enum {X} , that creates a global constant X (which can clash

Name spaces in C

↘锁芯ラ 提交于 2020-03-21 08:39:20
问题 I have the following code: typedef struct Y {int X;} X; enum E {X}; which generates a error: error: 'X' redeclared as different kind of symbol As I know, C has implicitly defined namespaces for structure, union, and enum tags and also for their members. So, I'm not sure why does E::X collide with typedef structure tag X ? What exactly are name spaces in C? 回答1: C does not have a separate namespace for enum members. When you write enum {X} , that creates a global constant X (which can clash

C99 inline function in .c file

China☆狼群 提交于 2020-02-23 09:24:32
问题 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? 回答1: 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

Local variable length array

不羁的心 提交于 2020-02-06 04:26:04
问题 during some code refactor in C++ i meet following local variable length arrays void some_function(uint8_t length, uint8_t id, uint8_t * bytes)) { uint8_t string[length + 8]; //some transformation on string [1-8] elements do_something(string); } I am not familiar with C99 but using Variable-length array size [x+y] look like this will be placed in heap. Also I debug this function to make sure that this "string" variable is placed on heap and it is. In C local variables can't be fixed size, so

error: unknown conversion type character 'l' in format - scanning long long

☆樱花仙子☆ 提交于 2020-02-01 10:06:39
问题 I'm trying to get long long from the console using standard IO function scanf . I started with %lld : scanf("%lld", &rule); That throws: error: unknown conversion type character 'l' in format [-Werror=format=] I've found more workarounds, but they too throw errors: scanf("%I64d", &rule); ->error: ISO C does not support the 'I64' ms_scanf length modifier [-Werror=format=] scanf("%"SCNd64"", &rule); ->error: expected ')' before 'SCNd64' Am I doing something wrong? Is there an another trick? I'm

Where in the C99 standard does it say that signed integer overflow is undefined behavior?

帅比萌擦擦* 提交于 2020-01-30 07:42:08
问题 Where in the C99 standard does it say that signed integer overflow is undefined behavior? I see the comment about unsigned integer overflow being well-defined (see Why is unsigned integer overflow defined behavior but signed integer overflow isn't?) in section 6.2.5: A computation involving unsigned operands can never overflow, because a result that cannot be represented by the resulting unsigned integer type is reduced modulo the number that is one greater than the largest value that can be

Where in the C99 standard does it say that signed integer overflow is undefined behavior?

二次信任 提交于 2020-01-30 07:42:07
问题 Where in the C99 standard does it say that signed integer overflow is undefined behavior? I see the comment about unsigned integer overflow being well-defined (see Why is unsigned integer overflow defined behavior but signed integer overflow isn't?) in section 6.2.5: A computation involving unsigned operands can never overflow, because a result that cannot be represented by the resulting unsigned integer type is reduced modulo the number that is one greater than the largest value that can be