compiler-warnings

Overflow in Constant Arithmetic When Using FLT_MAX

I have a warning in my C++ code, regarding the use of FLT_MAX. The code is (very simply): const float a_lot = FLT_MAX; The generated warning is: warning C4756: overflow in constant arithmetic And it doesn't help if I change the code to: const float a_lot = std::numeric_limits<float>::max(); I'm using Microsoft Visual Studio 2...

Add compiler flag for Visual Studio 2005 with CMake 2.8.1

Probably an easy beginners question: I want to add the compiler flag /EHsc to my project and tried both SET_TARGET_PROPERTIES(name_of_my_project PROPERTIES COMPILER_FLAGS "/EHsc") and SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHsc") in my CMakeLists.txt. With both, CMake generates a Visual Studio Solution without complaining. EDI...

Should I use secure versions of POSIX functions on MSVC - C

I am writing some C code which is expected to compile on multiple compilers (at least on MSVC and GCC). Since I am beginner in C, I have all warnings turned on and warnings are treated as errors (-Werror in GCC & /WX in MSVC) to prevent me from making silly mistakes. When I compiled some code that uses strcpy on MSVC, I get warning lik...

Toolkit returns references to proprietary Sun APIs?

I just upgraded our project to JDK 1.6, and on compilation, I have a test class that implements java.awt.Toolkit and implements the methods to do nothing special (other than capture the call to the beep command). (This is an old test that should probably be rewritten in several ways (either mock it or wrap that functionality in a simpl...

Should get 20 errors... but get 0... when compiling without declaring an instance variable.

In my iPhone apps I regularly do this in xCode v3.2.3: Declare a BOOL variable in the *.h file Use @property in the same *.h file. Use @sythesize in the matching *.m file. I accidentally forgot to do #1... but it still complied fine. 0 warnings. 0 errors. 0 analyzer errors. How can that be? Shouldn't my code to loaded with compil...

Visual C++ Warning C4800, why does it only trigger on return statements?

I have just installed the Windows SDK v7.1 (MSVC 10.0) and running my code through (almost) full warning level (W3, default for qmake's CONFIG += warn_on) and am surprised about warning C4800: 'type' : forcing value to bool 'true' or 'false' (performance warning) In the following code, stream is an std::istream and token is a std::strin...

How can I retain compiler warnings in Hudson (CI) when using SVN Update?

I've got a continuous integration setup using Hudson and lately I've configured the jobs to use svn update to get the latest version of the code. I really like this approach since it allows msbuild to version appropriately and only build the effected assemblies. However, I've noticed that since I'm not doing a build of all the assembli...

Initialise string function result?

I've just been debugging a problem with a function that returns a string that has got me worried. I've always assumed that the implicit Result variable for functions that return a string would be empty at the start of the function call, but the following (simplified) code produced an unexpected result: function TMyObject.GenerateInfo: s...

How to fix “No newline at end of file” compiler warning for lots of files

I have a huge number of source files that are all lacking a newline at the end. How do I automatically add a newline to the end of each of them? Some may already have a newline, so it should only be added if necessary. I'm probably not looking for code, per se, but just something I can run in Terminal to add the necessary newlines (or ...

When is "undefined" fatal or just warning?

test.c(6) : warning C4013: 'add' undefined; assuming extern returning int I've encountered many times when an undefined function will report an error,thus stopping the building process. Why this time just a warning? ...

What does "Lower precision in wider context" warning actually mean?

I have the following code, for an embedded platform where an int is 16 bits and a long int is 32 bits: #define MULTIPLIER 0x1000 static void my_function(uint16_t i, void *p) { uint32_t start = MULTIPLIER * i; ... } My compiler gives me the warning: Warning 1 : lower precision in wider context: '*' for this line. What does...

Problem using stringByReplacingOccurancesOfString in Objective-C

Hi, I'm having some problems working with NSStrings in Objective C... the code below returns a warning, saying: "'NSString' may not respond to '-stringByReplacingOccurancesOfString:withString:" NSString* NewWord = [Word stringByReplacingOccurancesOfString:@"!" withString:@""]; What ...

Java (Netbeans) compile error: "NSKeyBindingManager: Bad key binding atom"

I am getting an compiler warning / error at compile time using NetBeans 6.9 with some Java code that is: run: 2010-07-27 22:43:47.392 java[18743:903] NSKeyBindingManager: Bad key binding atom for '6' = 'D' BUILD SUCCESSFUL (total time: 5 seconds) The code still runs. Is this anything to worry about? I would post the code, but it se...

How to disable GCC warnings for a few lines of code

In Visual C++, it's possible to use #pragma warning (disable: ...). Also I found that in GCC you can override per file compiler flags. How can I do this for "next line", or with push/pop semantics around areas of code using GCC? ...

How does one suppress specific warnings from source code on g++ 4.5 or later?

The first comment on a feature request for g++ says, "Starting with 4.5 you can disable a class of warnings in the source." I looked through the 4.5.0 manual, but I can't find the syntax. What is the syntax in g++ 4.5 and later to suppress individual warning classes in the source? ...

Java - Accessing Static Method Sleep - What's wrong?

When I put the code below in NetBeans, NetBeans gives me a warning next to it saying "Accessing static method sleep". try { Thread.currentThread().sleep(2000); } catch(InterruptedException ie){ //continue } Am I doing something wrong? Should I be calling this differently? I'm n...

Java Deprecated Class using a Deprecated Class -- Can I turn off the compiler warning?

I am working on deprecating a set of Java classes so they aren't used anymore. I don't want to turn off the compiler warnings for deprecated usage, but I'm finding that if one of my deprecated classes imports another deprecated class I get a warning on that, too. I don't want to modify the code I'm deprecating, but I also don't want the ...

Compilation warning with Qt - Mac OS X only: <class> is already a friend of <class>

I am receiving the following warning when compiling a Qt project, but ONLY on Mac OS X with GCC. Windows with MinGW and Linux with GCC do not emit this warning. /Library/Frameworks/QtCore.framework/Versions/4/Headers/qtextcodec.h:175: warning: 'QCoreXmlStreamWriter' is already a friend of 'QTextEncoder' Why is this showing up and how c...

Dereferencing pointer does break strict anti-aliasing rules using Berkeley sockets

I've got code that looks something like this, where addr is a sockaddr*: struct sockaddr_in *sin = (struct sockaddr_in *) addr; const char *IP=inet_ntoa(sin -> sin_addr); I believe this is very typical code for using Berkeley sockets. However, when I compile this, I'm getting the following warning: dereferencing pointer 'sin' does br...

Is there compile warnings or errors for deprecated code in XCode for iOS4 projects by default?

Hi Everyone, I took over an iPhone project recently that was developed prior iOS4. I'm wondering if XCode would prompt warnings or errors on compile. It currently succeeds with "No issues" when built so is it safe to assert that it contains no deprecated code? Or is there a setting to be set on XCode to warn on compile for deprecated co...