compiler-warnings

Strange Java compiler warning: incorrect “potential null access warning”

柔情痞子 提交于 2019-12-10 23:56:44
问题 (JDK 1.6.0_23, Eclipse 3.7.0 with "Potential null pointer access" warning level at "Warning") Consider the following example code: Object obj = null; for (;;) { obj = getObject(); if (obj != null) break; Thread.sleep(25); } obj.toString(); I'm getting the following warning on the last line: Potential null pointer access: The variable obj may be null at this location . Is there any real way for obj to actually be null or why the compiler thinks so? 回答1: The compiler is seeing this as a

How to tell GCC to set structure size boundary to 4 bytes through compiler settings (not pragma's)?

不羁的心 提交于 2019-12-10 22:52:20
问题 I want my c++ program compiled under GCC to have maximum alignment of 4 bytes (of members of structures). I really can do this through #pragma pack directive. However, it's uncomfortable in my case because the project is quite big, and I would need to make a single header with #pragma pack, that has to be included everywhere. Now, the gcc compiler has an option -mstructure-size-boundary=n documented here http://gcc.gnu.org/onlinedocs/gcc/ARM-Options.html#ARM-Options , it says "Permissible

Strange SAL annotation warning

牧云@^-^@ 提交于 2019-12-10 21:25:41
问题 I'm trying to use Micosoft's SAL annotation for my project, however I get the following warning, and I don't know why. As an example, I created a new C++ console application, and have this code: #include <sal.h> class Whatever { public: _Check_return_ int Method(__in int number) ; }; int main() { return 0; } When I compile using Visual Studio 2008, I get the following warning: warning C6540: The use of attribute annotations on this function will invalidate all of its existing __declspec

MSVC equivalent of gcc/clang's -Wall?

拥有回忆 提交于 2019-12-10 19:15:54
问题 I often build C (and C++) code, using GCC (or clang) with the -Wall flag turned on. Now I happen to need to make sure a small C project, which builds fine on Linux with this flag, also builds on Windows with MSVC. However, if I run MSVC with -Wall , I get many warnings which I find rather spurious, such as: warning C4255: 'some_func': no function prototype given: converting '()' to '(void)' `warning C4820: 'some_struct': '4' bytes padding added after data member 'some_member' and so on. Now,

Warning - Initialization makes pointer from integer without a cast

依然范特西╮ 提交于 2019-12-10 19:03:33
问题 I found similar questions but I don't think they applied to my specific problem, so I'm sorry if they do! I'm learning C as a first year CS student and trying to make a quiz in C, but I can't get anywhere because every time I try to compile to see if it's working I get the message "warning: initialization makes pointer from integer without a cast." I've worked out all of the syntax errors (I think) but I just for the life of my can't figure this out. I've gone through all of my lecture slides

Why isn't gcc complaining about array bounds even if requested?

為{幸葍}努か 提交于 2019-12-10 18:44:35
问题 I'm using gcc 4.9.0 and I would like to see compiler warn me about exceeded array bounds. If I compile this int main() { int table[5]={0}; table[8] = 1234; int x = table[10]; } with g++ -O2 -Wall main.cpp -o main.exe I only get warning about unused x: main.cpp: In function 'int main()': main.cpp:8:7: warning: unused variable 'x' [-Wunused-variable] int x = table[10]; ^ From gcc documentation (https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html#Warning-Options) I see that -O2 together with

CUDA ptxas warnings (Stack size for entry)

故事扮演 提交于 2019-12-10 18:24:41
问题 I am getting the following warning which I dont understand when compiling CUDA code: CUDACOMPILE : ptxas warning : Stack size for entry function '_Z24gpu_kernel_get_3d_pointsiPK8RtmPointS1_PKfS3_P10RtmPoint3DPif' cannot be statically determined The kernel prototype is: __global__ void gpu_kernel_get_3d_points(int count1, const RtmPoint *pPoints1, const RtmPoint *pPoints2, const float *PL, const float *PR, RtmPoint3D *pPoints3D, int *pGlobalCount, float bbox) All the pointers are pointers to

How to resolve “Main module of program is empty: nothing will happen when it is run”

跟風遠走 提交于 2019-12-10 17:22:21
问题 I have two projects in an F# solution. 1. main project with [EntryPoint] and set as the StarUp project. 2. support, the second project, holds a group of support modules. I.e. they are only called and never initiate anything nor serve as the entry point nor are the StartUp project. For the last module in the support project, compiling in Visual Studio gives warning FS0988: Main module of program is empty; nothing will happen when it is run While using compiler option nowarn inline as #nowarn

Too many actual parameters for macro?

故事扮演 提交于 2019-12-10 17:19:10
问题 Code: #include <iostream> using namespace std; #define ADD(x,y) ((x)+(y)) int main( int argc, char** argv ) { cout << ADD(1,2,) << endl; return 0; } Compiler output: 1>Compiling... 1>main.cpp 1>c:\warn_test\main.cpp(9) : warning C4002: too many actual parameters for macro 'ADD' Why isn't this an error? g++ (GCC) 4.2.1 20070719 [FreeBSD] gives more reasonable (in my mind) output: main.cpp:9:18: error: macro "ADD" passed 3 arguments, but takes just 2 main.cpp: In function 'int main(int, char**)

How can I avoid synthetic access compiler warning with inline-anonymous class declaration and what does it mean?

家住魔仙堡 提交于 2019-12-10 16:47:00
问题 I have the following code: public class SomeClass { //InterfaceUpdateListener is an interface private InterfaceUpdateListener listener = new InterfaceUpdateListener(){ public void onUpdate() { SomeClass.this.someMethod(); //complier complains on this line of code } }; private void someMethod() { //do something in here on an update event occuring } //other code to register the listener with another class... } My compiler in Eclipse complains that Access to enclosing method 'someMethod' from