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
27
votes
3 answers

WARNING: "implicit declaration of function '...' is invalid in C99"

I'm getting this warning when I'm trying to compare RGB components of two UIColors In .h file, I declared this -(int) ColorDiff:(UIColor *) color1 :(UIColor *)color2; In .m file - (int) ColorDiff:(UIColor *) color1 :(UIColor *)color2{ ...…
JHHoang
  • 653
  • 1
  • 8
  • 22
27
votes
2 answers

Tell gcc that a function call will not return

I am using C99 under GCC. I have a function declared static inline in a header that I cannot modify. The function never returns but is not marked __attribute__((noreturn)). How can I call the function in a way that tells the compiler it will not…
Tom
  • 335
  • 2
  • 4
  • 6
26
votes
6 answers

Don't understand "assuming signed overflow" warning

I am getting: warning: assuming signed overflow does not occur when assuming that (X + c) < X is always false [-Wstrict-overflow] on this line: if ( this->m_PositionIndex[in] < this->m_EndIndex[in] ) m_PositionIndex and m_EndIndex of type…
David Doria
  • 9,873
  • 17
  • 85
  • 147
25
votes
9 answers

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

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…
mikeh
25
votes
2 answers

Disable warnings being treated as errors (cc1.exe)

I am developing a BREW application. When compiling the application to get a MOD file, I am continuously getting this error: cc1.exe: warnings being treated as errors I want to disable this warning. I have googled it, and many say disabling -werror…
Sarim Sidd
  • 2,166
  • 2
  • 22
  • 31
24
votes
6 answers

How to make gcc warn about passing wrong enum to a function

gcc doesn't seem to produce a warning with the following code. How can I get it to produce a warning? typedef enum { REG8_A, REG8_B, REG8_C }REG8; typedef enum { REG16_A, REG16_B, REG16_C }REG16; void function(REG8…
Rocketmagnet
  • 5,656
  • 8
  • 36
  • 47
23
votes
9 answers

Suppress Compiler warning Function declared never referenced

So i have some code like this: void foo (int, int); void bar ( ) { //Do Stuff #if (IMPORTANT == 1) foo (1, 2); #endif } When doing a compile without "IMPORTANT" I get a compiler Warning that foo is defined and never referenced.…
Jtello
  • 752
  • 1
  • 5
  • 17
22
votes
1 answer

Meaning of the g++ flags "-Wall", " -W", and "-Werror"

What are these and what do they do? -Wall -W -Werror I am using the terminal in Ubuntu to compile programs with this command: g++ -Wall -W -Werror main.cpp -o exec What is the explanation?
Mudit Kapoor
  • 351
  • 2
  • 3
  • 9
22
votes
3 answers

Why does GCC not warn for unreachable code?

Why doesn't GCC (4.6.3) give me any warning for the unreachable code in the below example? #include int status(void) { static int first_time = 1; if (first_time) { return 1; first_time = 0; /* Never reached */ …
Andreas Haas
  • 221
  • 2
  • 4
20
votes
2 answers

How to make gcc warn undefined struct?

I have a struct defined in .h struct buf_stats { // *** }; then in .c file struct buf_stats *bs = malloc(sizeof(struct buf_states*)) ; where buf_states is a typo. but gcc does not warn me, although I used -Wall and this bug/typo cost me 3 hours…
Sato
  • 8,192
  • 17
  • 60
  • 115
20
votes
4 answers

How to print the address of a function?

I let gcc compile the following example using -Wall -pedantic: #include int main(void) { printf("main: %p\n", main); /* line 5 */ printf("main: %p\n", (void*) main); /* line 6 */ return 0; } I get: main.c:5: warning: format ‘%p’…
alk
  • 69,737
  • 10
  • 105
  • 255
18
votes
5 answers

Error: this statement may fall through [-Werror=implicit-fallthrough=]

I am trying to compile mitk on ubuntu and I got this error : error: this statement may fall through [-Werror=implicit-fallthrough=] Here there is a part of code : /** Get memory offset for a given image index */ unsigned int…
agasim
  • 183
  • 1
  • 1
  • 4
18
votes
4 answers

Have compiler check the number of array initializers

Initializing an array (in C++, but any solution which works for C will likely work here as well) with less initializers than it has elements is perfectly legal: int array[10] = { 1, 2, 3 }; However, this can be a source of obscure bugs. Is there a…
MvG
  • 57,380
  • 22
  • 148
  • 276
17
votes
1 answer

GCC v12.1 warning about serial compilation

I have upgraded my whole arch linux system today (12th May, 2022). gcc was also upgraded from v11.2 to v12.1. I tried compiling some of my programs with g++ (part of gcc compiler collection) by the following command: g++ -O3 -DNDEBUG -Os -Ofast -Og…
Darth-CodeX
  • 2,166
  • 1
  • 6
  • 23
17
votes
3 answers

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

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…
maerics
  • 151,642
  • 46
  • 269
  • 291
1 2
3
54 55