Search code examples
gccgcc-warning

enforing check about returning a value in gcc


I am compiling some C/C++ files using gcc.

I noticed today a bug that caused my app to crash. It was caused by the fact that my function didn't return any value (see below). Do you know if there is some flag in gcc enforcing these kind of checking or why the compiler is not warning me about this?

I am compiling C files into object files with a basic -g -D_GNU_SOURCE -o outObjectFile -c myFile.c option.

   //.c file
   int
   myFunc(){
      ...do something
      ..without return statement
   }

   //.h file
   extern int myFun();

Solution

  • When using GCC, always compile with:

    -std=c99 -pedantic -Wall -Wextra -Wwrite-strings for C

    -ansi -pedantic -Wall -Wextra -Weffc++ for C++