compiler-warnings

Checking the gcc version in a Makefile?

怎甘沉沦 提交于 2019-11-27 01:19:00
问题 I would like to use some gcc warning switchs that aren't available in older gcc versions (eg. -Wtype-limits). Is there an easy way to check the gcc version and only add those extra options if a recent gcc is used ? 回答1: I wouldn't say its easy, but you can use the shell function of GNU make to execute a shell command like gcc --version and then use the ifeq conditional expression to check the version number and set your CFLAGS variable appropriately. Here's a quick example makefile: CC = gcc

Compiler warning - suggest parentheses around assignment used as truth value

試著忘記壹切 提交于 2019-11-27 00:58:54
When I try to compile the piece of code below, I get this warning: warning: suggest parentheses around assignment used as truth value Why does this happen? This is a rather common idiom, I believe. I even use something like it earlier on my code. struct PIDList* getRecordForPID(struct PIDList* list, pid_t pid) { while(list = list->next) if (list->pid == pid) return list; return NULL; } Be explicit - then the compiler won't warn that you perhaps made a mistake. while ( (list = list->next) != NULL ) or while ( (list = list->next) ) Some day you'll be glad the compiler told you, people do make

How to compile without warnings being treated as errors?

别等时光非礼了梦想. 提交于 2019-11-27 00:09:05
问题 The problem is that the same code that compiles well on Windows, is unable to compile on Ubuntu. Every time I get this error: cc1: warnings being treated as errors Now, it's big code base and I don't like fix all the warnings. Is there any way I can compile successfully in spite of the warnings? 回答1: Sure, find where -Werror is set and remove that flag. Then warnings will be only warnings. 回答2: You can make all warnings being treated as such using -Wno-error . You can make specific warnings

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

做~自己de王妃 提交于 2019-11-26 22:37:56
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? This is quite common when including jar files. Although the warning isn't anything to worry about if

Compiler warning for function defined without prototype in scope?

白昼怎懂夜的黑 提交于 2019-11-26 22:05:18
问题 [Question inspired by a comment thread at this answer.] As everyone knows, since C99 it's an error to call a function that hasn't been declared, preferably with a proper prototype. But, going beyond that, I want my compiler to warn me if I define a function without a prototype declaration in scope, presumably included out of the same header file that the callers are using. (Unless the function is static, in which case all of this is moot.) The reason should be obvious: If there's a prototype

not all code paths return a value

不羁岁月 提交于 2019-11-26 21:54:40
问题 I got this compiler error, what is the problem? public PictureBox getinfo(int i, int j) { return grid[i, j]; } public PictureBox kingmove(int i, int j)///<-----the problem is here { getinfo(i, j); if (i < 9) { grid[i, j] = grid[i - 1, j - 1]; } else { grid[i, j] = grid[i, j]; } 回答1: Your second method has no return statement but a return-type different from void . Add a return statement at the end of the method and not in the beginning. And you could have edited that into your previous

Compile time warning when using 'Microsoft.Office.Interop.Word._Document.Close'

可紊 提交于 2019-11-26 21:48:24
问题 Anyone know how to solve this warning message? Ambiguity between method 'Microsoft.Office.Interop.Word._Document.Close(ref object, ref object, ref object)' and non-method 'Microsoft.Office.Interop.Word.DocumentEvents2_Event.Close'. Using method group. 回答1: The only way I've managed to resolve the warning is to use an explicit cast: var doc_close = (Microsoft.Office.Interop.Word._Document) _doc; doc_close.Close(); If you already have a using for Microsoft.Office.Interop.Word you can simplify

Override compile flags for single files

雨燕双飞 提交于 2019-11-26 21:34:18
I would like to use a global set of flags for compiling a project, meaning that at my top-level CMakeLists.txt file I have specified: ADD_DEFINITIONS ( -Wall -Weffc++ -pedantic -std=c++0x ) However, for a specific file (let's say "foo.cpp") in a subdirectory, I want to switch the compile flags to not apply -Weffc++ (included commercial library I cannot change). To simplify the situation to use only -Wall, I tried: SET_SOURCE_FILES_PROPERTIES( foo.cpp PROPERTIES COMPILE_FLAGS -Wall ) ADD_EXECUTABLE( foo foo.cpp ) , which did not work. I also tried SET_PROPERTY( SOURCE foo.cpp PROPERTY COMPILE

warning: return type defaults to ‘int’ [-Wreturn-type]

筅森魡賤 提交于 2019-11-26 20:54:03
问题 I'm a Linux user who started learning C and I'm trying to compile this source that I typed: #include <stdio.h> main() { float c,d; c = 10215.3; d = c / 3; printf("%3.2f\n",d); return 0; } It compiled with this using a makefile that I wrote: cc -Wall -g printf.c -o printf but I'm getting this warning: printf.c:2:1: warning: return type defaults to ‘int’ [-Wreturn-type] it compiles the code and I get the desired output but I want to understand what this means 回答1: main() should be int main() In

Fix warning “C-style for Statement is deprecated” in Swift 3

生来就可爱ヽ(ⅴ<●) 提交于 2019-11-26 20:46:22
I have update Xcode to 7.3 and now I have a warning to the function that I use to create random strings. I have tried to change the for statement with for (i in 0 ..< len){...} however, the warning became an error. How can I remove the warning? static func randomStringWithLength (len : Int) -> NSString { let letters : NSString = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" let randomString : NSMutableString = NSMutableString(capacity: len) for (var i=0; i < len; i += 1){ // warning let length = UInt32 (letters.length) let rand = arc4random_uniform(length) randomString