gcc-warning

Why doesn't GCC produce a warning when assigning a signed literal to an unsigned type?

一笑奈何 提交于 2019-12-18 19:06:06
问题 Several questions on this website reveal pitfalls when mixing signed and unsigned types and most compilers seem to do a good job about generating warnings of this type. However, GCC doesn't seem to care when assigning a signed constant to an unsigned type! Consider the following program: /* foo.c */ #include <stdio.h> int main(void) { unsigned int x=20, y=-30; if (x > y) { printf("%d > %d\n", x, y); } else { printf("%d <= %d\n", x, y); } return 0; } Compilation with GCC 4.2.1 as below

Is there any way to get readable gcc error and warning output at the command line?

可紊 提交于 2019-12-18 10:47:45
问题 For some long errors, the gcc output is dense and has lots of line-wrapping etc. Especially when errors are subtle, it can take me 10-30 seconds of squinting to parse it with my eyes. I've taken to pasting this in an open code-editor window to get some basic syntax highlighting and enable reformatting with regex's. Has anyone invented a more automated method? 回答1: I use this script, called colorize : #!/bin/bash while read x ; do echo $x ; done \ | sed -e "s/.*error:.*/\x1b[1;36m&\x1b[0m/" \

GCC missing braces around initializer

霸气de小男生 提交于 2019-12-18 10:41:05
问题 I have this struct in C below that I want to initialize to all zero. How do I get rid of the missing braces warning? typedef struct { uint32_t incoming[FRAME_TYPE_MAX]; uint32_t outgoing[FRAME_TYPE_MAX]; uint32_t timeouts; uint32_t crc_errors; } pkt_t; static pkt_t stats = {0}; 回答1: This is GCC bug # 53119: http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53119 If you want to see it fixed, post a followup to the bug report indicating that it's a problem for you. 回答2: Since your first member in the

Confusion in regards to purpose/behavior of -Waggregate-return?

夙愿已清 提交于 2019-12-18 07:52:06
问题 While looking at the GCC's warning options, I came across -Waggregate-return . -Waggregate-return Warn if any functions that return structures or unions are defined or called. (In languages where you can return an array, this also elicits a warning.) small example that elicits the warning: class foo{}; foo f(void){return foo{};} int main(){} $ g++ -std=c++0x -Waggregate-return -o main main.cpp main.cpp: In function ‘foo f()’: main.cpp:2:5: warning: function returns an aggregate [-Waggregate

warning: implicit declaration of function ‘getresuid’ (and ‘seteuid’)

老子叫甜甜 提交于 2019-12-18 05:16:07
问题 I would like to get rid of the warnings. When I compile the source code with gcc -Wall -ansi -o test test.c I get back test.c: In function ‘main’: test.c:12: warning: implicit declaration of function ‘getresuid’ test.c:14: warning: implicit declaration of function ‘seteuid’ When I compile it without -ansi switch gcc -Wall -o test test.c I see on the terminal test.c: In function ‘main’: test.c:12: warning: implicit declaration of function ‘getresuid’ I would like to use -ansi switch and get

Remove #pragma once warnings

こ雲淡風輕ζ 提交于 2019-12-18 03:44:17
问题 I am using #pragma once in my .cpp s and .hpp s and because of that I get a warning for each file that uses it. I have not found any option to disable this kind of warning, only the thing of #ifndef MY_FILE_H #define MY_FILE_H /*...*/ #endif . So would you recommend me to replace each #pragma once with ifndef s? in header: #define MYFILE_H // all the header and in the other files: #ifndef MYFILE_H #include "myfile.hpp" #endif // the rest of the file What do you think, is it better to use it

Remove #pragma once warnings

和自甴很熟 提交于 2019-12-18 03:44:00
问题 I am using #pragma once in my .cpp s and .hpp s and because of that I get a warning for each file that uses it. I have not found any option to disable this kind of warning, only the thing of #ifndef MY_FILE_H #define MY_FILE_H /*...*/ #endif . So would you recommend me to replace each #pragma once with ifndef s? in header: #define MYFILE_H // all the header and in the other files: #ifndef MYFILE_H #include "myfile.hpp" #endif // the rest of the file What do you think, is it better to use it

GCC -Wuninitialized / -Wmaybe-uninitialized issues

こ雲淡風輕ζ 提交于 2019-12-18 03:15:10
问题 I am experiencing a very strange issue using gcc-4.7 (Ubuntu/Linaro 4.7.2-11precise2) 4.7.2 . I am unable to compile the following valid code without a warning: extern void dostuff(void); int test(int arg1, int arg2) { int ret; if (arg1) ret = arg2 ? 1 : 2; dostuff(); if (arg1) return ret; return 0; } Compile options and output: $ gcc-4.7 -o test.o -c -Os test.c -Wall test.c: In function ‘test’: test.c:5:6: warning: ‘ret’ may be used uninitialized in this function [-Wmaybe-uninitialized]

Make one gcc warning an error?

馋奶兔 提交于 2019-12-17 23:34:25
问题 I get this warning from GCC: warning: cannot pass objects of non-POD type 'class Something' through '...'; call will abort at runtime It's pretty deadly, especially since it calls an abort. Why isn't this an error? I would like to make it an error, but: How do I make a specific warning an error? Which warning is it? According to http://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html, -Wno-invalid-offsetof looks like the flag to hide it, but it doesn't 回答1: I'm not sure what the correct

MSVC equivalent of __attribute__ ((warn_unused_result))?

ぃ、小莉子 提交于 2019-12-17 16:30:11
问题 I'm finding __attribute__ ((warn_unused_result)) to be very useful as a means of encouraging developers not to ignore error codes returned by functions, but I need this to work with MSVC as well as gcc and gcc-compatible compilers such as ICC. Do the Microsoft Visual Studio C/C++ compilers have an equivalent mechanism ? (I've tried wading through MSDN without any luck so far.) 回答1: It's _Check_return_ . See here for examples of similar annotations and here for function behaviour. It's