LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   how to address warnings? (http://www.linuxquestions.org/questions/programming-9/how-to-address-warnings-895351/)

hajiman 08-03-2011 12:52 PM

how to address warnings?
 
I use gcc to compile a .c file and get the following warnings when I execute the make file:

gcc -c -std=c99 gps2.c
gps2.c: In function 'run_gps2':
gps2.c:253:5: warning: implicit declaration of function 'localtime_r'
gps2.c:257:5: warning: implicit declaration of function 'asctime_r'
gps2.c:274:13: warning: implicit declaration of function 'strerror_r'
gps2.c:348:21: warning: implicit declaration of function 'timersub'
gps2.c: In function 'get_GPRMC_record':
gps2.c:1397:17: warning: implicit declaration of function 'strsep'

I have the following includes at the top of gps2.c:
#include <string.h>
#include <time.h>

How do I address these warning?

When I compile with g++, I don't get these warnings, however, I need to use gcc, not g++:
e.g. g++ -c gps2.c

Thanks much!

paulsm4 08-03-2011 01:39 PM

Hi -

Code:

// PROBLEM:
gps2.c:253:5: warning: implicit declaration of function 'localtime_r'
gps2.c:257:5: warning: implicit declaration of function 'asctime_r'
gps2.c:274:13: warning: implicit declaration of function 'strerror_r'
...

Code:

// SOLUTION:
#include <time.h>
#include <string.h>

Except that you already ARE #includ'ing the necessary headers :(

SUGGESTION:
Look at /usr/include/string.h (for example):
Code:

#if defined __USE_XOPEN2K || defined __USE_MISC
/* Reentrant version of `strerror'.
  There are 2 flavors of `strerror_r', GNU which returns the string
  and may or may not use the supplied temporary buffer and POSIX one
  which fills the string into the buffer.
  To use the POSIX version, -D_XOPEN_SOURCE=600 or -D_POSIX_C_SOURCE=200112L
  without -D_GNU_SOURCE is needed, otherwise the GNU version is
  preferred.  */
  ...

SUGGESTIONS:
1. Try compiling *without* the "c99" (if possible)
2. Try different combinations of "-D"

hajiman 08-03-2011 04:18 PM

> 1. Try compiling *without* the "c99" (if possible)

The problem goes away when the c99 option is not used. I used that option because it allows me to declare a variable in a for loop statement.
for (int i = 0; i < x; i++)
I've changed my code so that I can live without the c99 option. The warnings are rather quirky if the c99 option causes them.

Thanks for your suggestions.


All times are GMT -5. The time now is 02:32 AM.