compiler-warnings

Can I make GCC warn on passing too-wide types to functions?

瘦欲@ 提交于 2019-12-17 07:50:33
问题 Following is some obviously-defective code for which I think the compiler should emit a diagnostic. But neither gcc nor g++ does, even with all the warnings options I could think of: -pedantic -Wall -Wextra #include <stdio.h> short f(short x) { return x; } int main() { long x = 0x10000007; /* bigger than short */ printf("%d\n", f(x)); /* hoping for a warning here */ return 0; } Is there a way to make gcc and g++ warn about this? On a side note, do you have another compiler which warns about

Can I make GCC warn on passing too-wide types to functions?

断了今生、忘了曾经 提交于 2019-12-17 07:49:46
问题 Following is some obviously-defective code for which I think the compiler should emit a diagnostic. But neither gcc nor g++ does, even with all the warnings options I could think of: -pedantic -Wall -Wextra #include <stdio.h> short f(short x) { return x; } int main() { long x = 0x10000007; /* bigger than short */ printf("%d\n", f(x)); /* hoping for a warning here */ return 0; } Is there a way to make gcc and g++ warn about this? On a side note, do you have another compiler which warns about

Can I make GCC warn on passing too-wide types to functions?

亡梦爱人 提交于 2019-12-17 07:49:11
问题 Following is some obviously-defective code for which I think the compiler should emit a diagnostic. But neither gcc nor g++ does, even with all the warnings options I could think of: -pedantic -Wall -Wextra #include <stdio.h> short f(short x) { return x; } int main() { long x = 0x10000007; /* bigger than short */ printf("%d\n", f(x)); /* hoping for a warning here */ return 0; } Is there a way to make gcc and g++ warn about this? On a side note, do you have another compiler which warns about

What is “android:allowBackup”?

扶醉桌前 提交于 2019-12-17 06:58:06
问题 Since the new ADT preview version (version 21), they have a new lint warning that tells me the next thing on the manifest file (in the application tag): Should explicitly set android:allowBackup to true or false (it's true by default, and that can have some security implications for the application's data) In the official website, they've written: A couple of new checks: you must explicitly decide whether your app allows backups, and a label check. There's a new command line flag for setting

What is the “Ignoring InnerClasses attribute” warning output during compilation?

試著忘記壹切 提交于 2019-12-17 06:11:46
问题 I am new to Android and am using the Ical4j library for parsing ICS (Outlook calendar) files. However, when I build my application in Eclipse, the following warning appears many times in the console: [2010-07-22 15:58:31 - Google Calendar Upload] warning: Ignoring InnerClasses attribute for an anonymous inner class that doesn't come with an associated EnclosingMethod attribute. (This class was probably produced by a broken compiler.) Which implications does this have? How can I resolve this?

What does casting to `void` really do?

和自甴很熟 提交于 2019-12-17 05:04:59
问题 An often used statement like (void)x; allows to suppress warnings about unused variable x . But if I try compiling the following, I get some results I don't quite understand: int main() { int x; (short)x; (void)x; (int)x; } Compiling this with g++, I get the following warnings: $ g++ test.cpp -Wall -Wextra -o test test.cpp: In function ‘int main()’: test.cpp:4:13: warning: statement has no effect [-Wunused-value] (short)x; ^ test.cpp:6:11: warning: statement has no effect [-Wunused-value]

What's up with the thousands of warnings in standard headers in MSVC -Wall?

左心房为你撑大大i 提交于 2019-12-17 04:59:13
问题 Some people seem to advise you use -Wall, but when I did it on a small test project which just has a main.cpp with some includes, I get 5800 warnings most of them in standard headers or in windows headers. Is that intended behaviour? How do I go about making my compilation warning free? Here are just a few for some reading fun: 1>c:\program files\microsoft visual studio 10.0\vc\include\stdint.h(105): warning C4668: '_INTPTR' is not defined as a preprocessor macro, replacing with '0' for '#if/

Objective-C implicit conversion loses integer precision 'NSUInteger' (aka 'unsigned long') to 'int' warning

一曲冷凌霜 提交于 2019-12-17 04:11:32
问题 I'm working through some exercises and have got a warning that states: Implicit conversion loses integer precision: 'NSUInteger' (aka 'unsigned long') to 'int' #import <Foundation/Foundation.h> int main (int argc, const char * argv[]) { @autoreleasepool { NSArray *myColors; int i; int count; myColors = @[@"Red", @"Green", @"Blue", @"Yellow"]; count = myColors.count; // <<< issue warning here for (i = 0; i < count; i++) NSLog (@"Element %i = %@", i, [myColors objectAtIndex: i]); } return 0; }

Property getters and setters

北城以北 提交于 2019-12-17 03:25:15
问题 With this simple class I am getting the compiler warning Attempting to modify/access x within its own setter/getter and when I use it like this: var p: point = Point() p.x = 12 I get an EXC_BAD_ACCESS. How can I do this without explicit backing ivars? class Point { var x: Int { set { x = newValue * 2 //Error } get { return x / 2 //Error } } // ... } 回答1: Setters and Getters apply to computed properties ; such properties do not have storage in the instance - the value from the getter is meant

Why should I always enable compiler warnings?

不打扰是莪最后的温柔 提交于 2019-12-16 20:00:47
问题 I often hear that when compiling C and C++ programs I should "always enable compiler warnings". Why is this necessary? How do I do that? Sometimes I also hear that I should "treat warnings as errors". Should I? How do I do that? 回答1: Why enable warnings? C and C++ compilers are notoriously bad at reporting some common programmer mistakes by default , such as: forgetting to initialise a variable forgetting to return a value from a function arguments in printf and scanf families not matching