compiler-warnings

gcc failing to warn of uninitialized variable

て烟熏妆下的殇ゞ 提交于 2019-11-26 11:35:36
问题 The following code has a variable that may be uninitialized. It seems that gcc should be generating a warning but isn\'t: $ cat a.c int foo(int b) { int a; if (b) a = 1; return a; } $ gcc-4.7 -c -Wall -Wmaybe-uninitialized -o a.o ./a.c $ gcc-4.7 -v Using built-in specs. COLLECT_GCC=gcc-4.7 COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/4.7/lto-wrapper Target: x86_64-linux-gnu Configured with: ../src/configure -v --with-pkgversion=\'Ubuntu/Linaro 4.7.3-2ubuntu1~12.04\' --with-bugurl=file://

What are the valid characters for macro names?

僤鯓⒐⒋嵵緔 提交于 2019-11-26 11:23:22
Are C-style macro names subject to the same naming rules as identifiers? After a compiler upgrade, it is now emitting this warning for a legacy application: warning #3649-D: white space is required between the macro name "CHAR_" and its replacement text #define CHAR_& 38 This line of code is defining an ASCII value constant for an ampersand. #define DOL_SN 36 #define PERCENT 37 #define CHAR_& 38 #define RT_SING 39 #define LF_PAR 40 I assume that this definition (not actually referenced by any code, as far as I can tell) is buggy and should be changed to something like "CHAR_AMPERSAND"? Macro

Will a “variableName;” C++ statement be a no-op at all times?

点点圈 提交于 2019-11-26 10:52:22
问题 In C++ sometimes a variable will be defined, but not used. Here\'s an example - a function for use with COM_INTERFACE_ENTRY_FUNC_BLIND ATL macro: HRESULT WINAPI blindQuery( void* /*currentObject*/, REFIID iid, void** ppv, DWORD_PTR /*param*/ ) { DEBUG_LOG( __FUNCTION__ ); //DEBUG_LOG macro expands to an empty string in non-debug DEBUG_LOG( iid ); iid; // <<<<<<<----silence compiler warning if( ppv == 0 ) { return E_POINTER; } *ppv = 0; return E_NOINTERFACE; } In the above example iid

disable specific warnings in gcc [duplicate]

被刻印的时光 ゝ 提交于 2019-11-26 09:44:03
问题 This question already has answers here : Selectively disable GCC warnings for only part of a translation unit? (4 answers) Selectively remove warning message GCC (4 answers) Closed 3 months ago . On microsoft compilers, specific warnings can be disabled with a #pragma, without disabling other warnings. This is an extremely useful feature if the compiler warns over something that \"has to be done\". Does GCC at this point have a similar feature? It seems like an obvious enough feature that its

Compiler warning - suggest parentheses around assignment used as truth value

你说的曾经没有我的故事 提交于 2019-11-26 09:32:46
问题 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; } 回答1: Be explicit - then the compiler won't warn that you perhaps made a mistake. while ( (list = list->next)

Dynamic forwarding: suppress Incomplete Implementation warning

╄→尐↘猪︶ㄣ 提交于 2019-11-26 09:18:36
问题 I have a class exposing some methods, whose implementation is provided by an inner object. I\'m using forward invocation to dispatch at runtime the method calls to the inner object, but XCode is complaining since it cannot find an implementation of the declared methods. I found some other similar questions on SO, but all of them were solved with a design change. I don\'t mean to have a discussion about the design here, but if anybody has some suggestion about it I have an open question on

Override compile flags for single files

泪湿孤枕 提交于 2019-11-26 08:01:47
问题 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

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

泄露秘密 提交于 2019-11-26 07:43:37
问题 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){

Why does C++ code missing a formal argument name in a function definition compile without warnings?

血红的双手。 提交于 2019-11-26 06:37:13
问题 While getting started with some VS2005-generated MFC code, I noticed it overrode a method with something like this: void OnDraw(CDC* /*pDC*/) { ... // TODO: Add your code here } So of course, as soon as I added something I realized I needed to un-comment the pDC formal argument in order to compile, but I\'m confused as to how/why a C++ function can compile (with no warnings) when the formal argument only has a type and not a name: void foo(int) { int x = 3; } int main() { foo(5); return 0; }

What does i = (i, ++i, 1) + 1; do?

♀尐吖头ヾ 提交于 2019-11-26 05:55:49
问题 After reading this answer about undefined behavior and sequence points, I wrote a small program: #include <stdio.h> int main(void) { int i = 5; i = (i, ++i, 1) + 1; printf(\"%d\\n\", i); return 0; } The output is 2 . Oh God, I didn\'t see the decrement coming! What is happening here? Also, while compiling the above code, I got a warning saying: px.c:5:8: warning: left-hand operand of comma expression has no effect [-Wunused-value] i = (i, ++i, 1) + 1; ^ Why? But probably it will be