compiler-warnings

warning: implicit declaration of function ‘getresuid’ (and ‘seteuid’)

余生长醉 提交于 2019-11-29 08:42:58
I would like to get rid of the warnings. When I compile the source code with gcc -Wall -ansi -o test test.c I get back test.c: In function ‘main’: test.c:12: warning: implicit declaration of function ‘getresuid’ test.c:14: warning: implicit declaration of function ‘seteuid’ When I compile it without -ansi switch gcc -Wall -o test test.c I see on the terminal test.c: In function ‘main’: test.c:12: warning: implicit declaration of function ‘getresuid’ I would like to use -ansi switch and get rid of warnings. How can I achieve my goal ? /* this is the test.c */ #include <stdio.h> #include <sys

How do I enable the 6000 series warnings (code analysis warnings) in MSVC++?

安稳与你 提交于 2019-11-29 08:30:48
Even warning level 4 and "all warnings" does not make the 6000 series warnings appear. Actually enabling these "Code Analysis" warnings has it's own dialog. In your project properties, you must check "Enable Code Analysis on Build" to make it work. This code should then show error 6246: #include <stdio.h> int main() { int x ; { int x = 6 ; printf( "%d\n", x ) ; } } warning C6246: Local declaration of 'x' hides declaration of the same name in outer scope. This setting appears to be completely independent of the "Configuration Properties/C/C++/General/Warning Level" setting in the properties

Can GCC warn me about modifying the fields of a const struct in C99?

痞子三分冷 提交于 2019-11-29 05:57:57
问题 I stumbled upon a small issue while trying to make const-correct code. I would have liked to write a function that takes a pointer to a const struct, to tell to the compiler "please tell me if I am modifying the struct, because I really do not want to". It suddenly came to my mind that the compiler will allow me to do this: struct A { char *ptrChar; }; void f(const struct A *ptrA) { ptrA->ptrChar[0] = 'A'; // NOT DESIRED!! } Which is understandable, because what actually is const is the

Is there an equivalent of gcc's -Wshadow in visual C++

房东的猫 提交于 2019-11-29 05:31:58
-Wshadow will "Warn whenever a local variable shadows another local variable.". Is there an equivalent in Visual C++ (2008)? I tried /W4 but it didn't pick up on it. I also tried Cppcheck but that didn't see it either. e.g. if I inadvertently do: class A { private: int memberVar; public: void fn() { int memberVar = 27; } }; I would really like to know about it! I am afraid no. You could perhaps try compiling your code with Clang: it has this warning (and a lot of others) it has a compatibility mode for MSVC headers (and can build most of MFC) We use gcc at work, to build our code, but compile

Turn off Xcode's unused variable warnings while typing

和自甴很熟 提交于 2019-11-29 05:30:26
I'm sick to death of Xcode's prolific use of live "unused variable" warnings while I am typing. I keep thinking I have an error in my syntax, stop what I'm doing, check the warning, only to see it's an unused variable warning. Of course it's unused, I just typed it! I don't mind the compile-time unused variable warnings, those are very useful, but I hate the live warnings as I'm typing code. Is there any way I can turn off this warning completely everywhere, either app-wide or for an entire project? dfri It seems as of currently, we cannot suppress specific warnings in the way #pragma clang

Why didn't the compiler warn me about an empty if-statement?

三世轮回 提交于 2019-11-29 05:28:09
I'm using Keil uVision v4.74 and have enabled the option "All Warnings". I wrote the following intentional code: if(condition matched) { //do something } When I rebuilt my project, I got 0 errors, 0 warnings. However, when I accidentally wrote: if(condition matched); { //do something } I also got 0 errors, 0 warnings. It was next to impossible for me to find out that a small ; following the if condition was the root of the problem. Why didn't the compiler treat it as a warning and inform me? It's not an error because an empty statement is a valid statement; however, since it's certainly

Is there a way to suppress warnings in C# similar to Java's @SuppressWarnings annotation?

我的未来我决定 提交于 2019-11-29 05:27:37
Is there a way to suppress warnings in C# similar to Java's @SuppressWarnings annotation? Failing that, is there another way to suppress warnings in Visual Studio? Yes. For disabling, use : #pragma warning disable 0169, 0414, anyothernumber Where the numbers are the identifiers of the warnings that you can read from compiler output. To reenable the warnings after a particular part of code (which is a good idea) use: #pragma warning restore 0169, anythingelse This way you can make the compiler output clean, and keep yourself safe because the warnings will only be suppressed for that particular

The parameter 'foo' should not be assigned — what's the harm?

天大地大妈咪最大 提交于 2019-11-29 05:26:46
Compare this method: void doStuff(String val) { if (val == null) { val = DEFAULT_VALUE; } // lots of complex processing on val } ... to this method: void doStuff(String origVal) { String val = origVal; if (val == null) { val = DEFAULT_VALUE; } // lots of complex processing on val } For the former method, Eclipse emits the warning "The parameter 'val' should not be assigned". Why? To my eye, the former is cleaner. For one thing, it doesn't force me to come up with two good names for val (coming up with one good one is hard enough). (Note: Assume there is no field named val in the enclosing

Why compiler is not giving error when signed value is assigned to unsigned integer? - C++

邮差的信 提交于 2019-11-29 03:12:32
I know unsigned int can't hold negative values. But the following code compiles without any errors/warnings. unsigned int a = -10; When I print the variable a , I get a wrong value printed. If unsigned variables can't hold signed values, why do compilers allow them to compile without giving any error/warning? Any thoughts? Edit Compiler : VC++ compiler Solution Need to use the warning level 4. Microsoft Visual C++: warning C4245: 'initializing' : conversion from 'int' to 'unsigned int', signed/unsigned mismatch On warning level 4. G++ Gives me the warning: warning: converting of negative value

Significance of const keyword positioning in variable declarations

白昼怎懂夜的黑 提交于 2019-11-29 02:46:27
问题 What is the significance of the positioning of the const keyword when declaring a variable in Objective-C, for example: extern const NSString * MY_CONSTANT; versus extern NSString * const MY_CONSTANT; Using the first version in assignments produces warnings about "qualifiers from pointer target type" being discarded so I'm assuming that the second version ensures that the pointer address remains the same. I would really appreciate a more definitive answer though. Many thanks in advance! 回答1: