c99

C99 Designated Initializer duplicate index not flagged at all in build output or lint

倖福魔咒の 提交于 2019-12-23 18:23:24
问题 I played around with designated initializers a bit the other day and noticed, to my surprise, that it is valid to use the same index more than once. What's more, it didn't even produce a compiler warning, error, or even informational statement when I did so, and even PC-Lint didn't seem to care (which I think surprised me the most). I'm wondering if there's a reason for compilers not even providing an information message in this case or if there are additional compiler/lint/etc. options that

Supply C99 complex arguments from C++ [duplicate]

£可爱£侵袭症+ 提交于 2019-12-23 18:19:47
问题 This question already has an answer here : Closed 6 years ago . Possible Duplicate: Passing a C++ complex array to C If a third party C library expects an array of C99 complex numbers as an argument, what is the easiest way to call it from C++, where my complex numbers use the STL complex type? I could just wrap it in a new c function that accepts floats and converts them to complex, but is there a more direct way to do it? 回答1: According to C99: 6.2.5/13 Each complex type has the same

How to use ftruncate in c99 without warning

梦想与她 提交于 2019-12-23 09:57:34
问题 I want to use ftruncate function in my code. I have to compile with option std=c99. I get warning: In function ‘test’: warning: implicit declaration of function ‘ftruncate’ [-Wimplicit-function-declaration] I tied to find on the Internet any solution which can solve this problem but I don't succeeded in. I use ftrucnate because I want to clear content of an opened file after I get lock (flock). 回答1: Since ftruncate() isn't a standard C function, and you've asked for standards enforcement, you

Returning a variable while using a post increment in C

巧了我就是萌 提交于 2019-12-23 08:56:08
问题 I have a global variable called var and a function foo . (I know it's a bad practice but sometimes it's unavoidable) I'm wondering if the C standard (I'm compiling using c99) says what happens to var if I try to execute: long foo(){ return var++; } Thanks. 回答1: Short answer: It will return a copy of var and then immediately afterwards increment the global var . Long answer: C11 6.5.2.4 "The result of the postfix ++ operator is the value of the operand. As a side effect, the value of the

Is a goto in alloca's function scope valid?

浪子不回头ぞ 提交于 2019-12-23 07:29:26
问题 The C standard prohibits a goto into a function scope where a VLA exists. A VLA and the call to alloca function should have the same result on low level. (I could be wrong, as I'm just a C, not a low level programmer, but in my imagin that appears to be witty) So will the following snippet be also undefined behaivng? int main() { char *p; goto label1; { p = _alloca(1); label1: p = NULL; } } Ofcourse I cant refference p , but whats about the behaviour? 回答1: Actually, the rule 6.8.6.1 states: A

When compiled it is showing warning:cannot find entry symbol Rrors;defaulting to 0000000000400590

元气小坏坏 提交于 2019-12-23 06:09:37
问题 the while loop is not working here.there is no compilation error and the print statement is also getting executed in the beggining.the code works fine without the while loop.the code is to print the most repeating letter in a string and the number of times it is repeated #include <stdio.h> #include <string.h> int main(void) { int t; int tempC; scanf("%d",&t); while ( (tempC = getchar()) != '\n' && tempC != EOF ); while(t--) { char c[100]; char r='z'; int i,j=0,count,a,k,amx; gets(c); k=strlen

Why does packing not work across sibling unions or structs

自闭症网瘾萝莉.ら 提交于 2019-12-23 03:03:44
问题 In the following example I expect the size of complex_t to be the same as uint16_t : 2 bytes, however it's 3 bytes. Removing the second union ("proximity_unsafe") reduces the size to 2 bytes, but I can't figure out the model of the packing rules. #include <stdint.h> #include <stdio.h> typedef union { uint16_t unsafe; struct { uint16_t backwardmotion_unsafe : 1; uint16_t batteryvoltage_unsafe : 1; union { uint16_t dropoff_unsafe : 4; struct { uint16_t dropofffrontleft_unsafe : 1; uint16_t

Strict aliasing rules for allocated objects

十年热恋 提交于 2019-12-22 10:38:09
问题 C99 6.5/6 The effective type of an object for an access to its stored value is the declared type of the object, if any. 75) If a value is stored into an object having no declared type through an lvalue having a type that is not a character type, then the type of the lvalue becomes the effective type of the object for that access and for subsequent accesses that do not modify the stored value. If a value is copied into an object having no declared type using memcpy or memmove, or is copied as

Why are no strict-aliasing warnings generated for this code?

拈花ヽ惹草 提交于 2019-12-22 08:36:40
问题 I have the following code: struct A { short b; }; struct B { double a; }; void foo (struct B* src) { struct B* b = src; struct A* a = (struct A*)src; b->a = sin(rand()); if(a->b == rand()) { printf("Where are you strict aliasing warnings?\n"); } } I'm compiling the code with the following command line: gcc -c -std=c99 -Wstrict-aliasing=2 -Wall -fstrict-aliasing -O3 foo.c I'm using GCC 4.5.0. I expected the compiler to print out the warning: warning: dereferencing type-punned pointer will

Is there a reason that C99 doesn't support function overloading?

会有一股神秘感。 提交于 2019-12-22 05:37:18
问题 Apparently (at least according to gcc -std=c99 ) C99 doesn't support function overloading. The reason for not supporting some new feature in C is usually backward compatibility, but in this case I can't think of a single case in which function overloading would break backward compatibility. What is the reasoning behind not including this basic feature? 回答1: To understand why you aren't likely to see overloading in C, it might help to better learn how overloading is handled by C++. After