Questions tagged [gcc-warning]

GCC is the GNU Compiler Collection, encompassing the gcc C compiler and the g++ C++ compiler, among others. It has powerful warning facilities that can reveal coding errors in C and C++ code.

GCC is the GNU Compiler Collection, a collection of language compilers that use the same underlying infrastructure. The most prominent are gcc, for C, and g++, for C++. All GCC compilers have similar warning facilities, starting with -Wall and including many other -W flags. These warnings can be extremely helpful in diagnosing problems with code and improving coding style and portability.

824 questions
319
votes
23 answers

How do I best silence a warning about unused variables?

I have a cross platform application and in a few of my functions not all the values passed to functions are utilised. Hence I get a warning from GCC telling me that there are unused variables. What would be the best way of coding around the…
Phil Hannent
  • 12,047
  • 17
  • 71
  • 118
267
votes
13 answers

How can I suppress "unused parameter" warnings in C?

For instance: Bool NullFunc(const struct timespec *when, const char *who) { return TRUE; } In C++ I was able to put a /*...*/ comment around the parameters. But not in C of course, where it gives me the error: error: parameter name omitted
nixgadget
  • 6,983
  • 16
  • 70
  • 103
254
votes
8 answers

How can I turn on (literally) ALL of GCC's warnings?

I would like to enable—literally—all of the warnings that GCC has. (You'd think it would be easy...) You'd think -Wall might do the trick, but nope! You still need -Wextra. You'd think -Wextra might do the trick, but nope! Not all of the warnings…
user541686
  • 205,094
  • 128
  • 528
  • 886
198
votes
2 answers

What is &&& operation in C

#include volatile int i; int main() { int c; for (i = 0; i < 3; i++) { c = i &&& i; printf("%d\n", c); } return 0; } The output of the above program compiled using gcc is 0 1 1 With the -Wall or…
manav m-n
  • 11,136
  • 23
  • 74
  • 97
172
votes
4 answers

warning: incompatible implicit declaration of built-in function ‘xyz’

I'm getting a number of these warnings when compiling a few binaries: warning: incompatible implicit declaration of built-in function ‘strcpy’ warning: incompatible implicit declaration of built-in function ‘strlen’ warning: incompatible implicit…
Alex Reynolds
  • 95,983
  • 54
  • 240
  • 345
165
votes
10 answers

How to suppress GCC warnings from library headers?

I have a project that uses log4cxx, boost, etc. libraries whose headers generate lots of (repetitive) warnings. Is there a way to suppress warnings from library includes (i.e. #include ) or includes from certain paths? I'd like to use…
AdSR
  • 2,097
  • 3
  • 15
  • 9
98
votes
1 answer

What exactly does GCC's -Wpsabi option do? What are the implications of supressing it?

Background In the last year I was using the nlohmann json library[1] and was cross-compiling on x86_64 using GCC 5.x arm-linux-gnueabi-* with no warnings. When I updated GCC to a newer version, GCC would generate pages of cryptic diagnostic notes.…
rmc
  • 1,118
  • 1
  • 7
  • 9
95
votes
8 answers

Pedantic gcc warning: type qualifiers on function return type

When I compiled my C++ code with GCC 4.3 for the first time, (after having compiled it successfully with no warnings on 4.1, 4.0, 3.4 with the -Wall -Wextra options) I suddenly got a bunch of errors of the form warning: type qualifiers ignored on…
Seth Johnson
  • 14,762
  • 6
  • 59
  • 85
80
votes
2 answers

Compile and run program without main() in C

I'm trying to compile and run following program without main() function in C. I have compiled my program using the following command. gcc -nostartfiles nomain.c And compiler gives warning /usr/bin/ld: warning: cannot find entry symbol _start;…
msc
  • 33,420
  • 29
  • 119
  • 214
63
votes
4 answers

Is there a GCC option to warn about writing `this-field` instead of `this->field`?

This following code (containing a vicious bug) compiles with GCC without any warning. But, of course, it doesn't work as expected by the developer (me). #include struct A { bool b; void set(bool b_) { this->b = b_; } bool…
Caduchon
  • 4,574
  • 4
  • 26
  • 67
63
votes
2 answers

function declared static but never defined

I have a header file suppose abc.h, where i have function declaration as: static int function1(); I have included this header file in abc.c and has defined the function and used it. static int function1() { < function definition> } After…
pankanaj
  • 903
  • 3
  • 10
  • 13
61
votes
3 answers

C warning implicit declaration of function 'exit'

This is my warning. implicit declaration of function 'exit' How i can remove it. i am using linux & gcc compiler.
ambika
  • 1,643
  • 5
  • 19
  • 18
56
votes
4 answers

How to circumvent format-truncation warning in GCC?

I'm getting the following gcc format-truncation warning: test.c:8:33: warning: ‘/input’ directive output may be truncated writing 6 bytes into a region of size between 1 and 20 [-Wformat-truncation=] snprintf(dst, sizeof(dst), "%s-more", src); …
Marius Melzer
  • 863
  • 1
  • 7
  • 10
52
votes
6 answers

Is there a way to get warned about unused functions?

I'd like to find unused functions in a codebase - including across compilations units. I'm using gcc as my compiler. Here's an example: foo.c (assume appropriate foo.h): void foo() { .... } void bar() { .... } main.c: #include…
Timothy Jones
  • 21,495
  • 6
  • 60
  • 90
52
votes
4 answers

How can I get rid of deprecated warnings in deprecated functions in GCC?

One way to implement deprecation warnings is to produce warnings on calls to deprecated functions, unless you are calling from a deprecated context. This way legacy code can call legacy code without producing warnings that only amount to noise. This…
Magnus Hoff
  • 21,529
  • 9
  • 63
  • 82
1
2 3
54 55