Abruzzo Forte e Gentile
Abruzzo Forte e Gentile

Reputation: 14869

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();

Upvotes: 0

Views: 187

Answers (1)

Šimon Tóth
Šimon Tóth

Reputation: 36433

When using GCC, always compile with:

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

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

Upvotes: 1

Related Questions