fix "warning: declaration of 'time' shadows a global declaration" (-Wshadow)

This warning occurred when compiling using

gcc (GCC) 4.4.7 20120313 (Red Hat 4.4.7-3)

on CentOS 6.5 x86_64

using the following CFLAGS (locally inserted into Makefile)

CFLAGS = -g -Wall -Wextra -Wformat=2 -funsigned-char -fstrict-aliasing
 -Wstrict-aliasing -Wfloat-equal -Wundef -Wuninitialized -Wpointer-arith
 -Wbad-function-cast -Wcast-qual -Wcast-align -Wwrite-strings -Waddress
 -Waggregate-return -Wstrict-prototypes -Wold-style-declaration
 -Wold-style-definition -Wmissing-parameter-type -Wmissing-prototypes
 -Wmissing-declarations -Wmissing-field-initializers -Wmissing-noreturn
 -Wmissing-format-attribute -Wpacked -Wredundant-decls -Wnested-externs
 -Wshadow -Wsign-compare -Wlogical-op -std=c99

and this make command:

make clean ; make example tests
This commit is contained in:
Evgueni Souleimanov 2014-06-16 20:49:47 -04:00
parent 82b1c180f2
commit 1b3147c7e0
3 changed files with 51 additions and 51 deletions

View File

@ -252,7 +252,7 @@ bool minmea_scan(const char *sentence, const char *format, ...)
} break; } break;
case 'T': { // Time (int, int, int, int), -1 if empty. case 'T': { // Time (int, int, int, int), -1 if empty.
struct minmea_time *time = va_arg(ap, struct minmea_time *); struct minmea_time *time_ = va_arg(ap, struct minmea_time *);
int h = -1, i = -1, s = -1, u = -1; int h = -1, i = -1, s = -1, u = -1;
@ -281,10 +281,10 @@ bool minmea_scan(const char *sentence, const char *format, ...)
} }
} }
time->hours = h; time_->hours = h;
time->minutes = i; time_->minutes = i;
time->seconds = s; time_->seconds = s;
time->microseconds = u; time_->microseconds = u;
} break; } break;
case '_': { // Ignore the field. case '_': { // Ignore the field.
@ -513,9 +513,9 @@ bool minmea_parse_gsv(struct minmea_sentence_gsv *frame, const char *sentence)
return true; return true;
} }
int minmea_gettimeofday(struct timeval *tv, const struct minmea_date *date, const struct minmea_time *time) int minmea_gettimeofday(struct timeval *tv, const struct minmea_date *date, const struct minmea_time *time_)
{ {
if (date->year == -1 || time->hours == -1) if (date->year == -1 || time_->hours == -1)
return -1; return -1;
struct tm tm; struct tm tm;
@ -523,14 +523,14 @@ int minmea_gettimeofday(struct timeval *tv, const struct minmea_date *date, cons
tm.tm_year = 2000 + date->year - 1900; tm.tm_year = 2000 + date->year - 1900;
tm.tm_mon = date->month - 1; tm.tm_mon = date->month - 1;
tm.tm_mday = date->day; tm.tm_mday = date->day;
tm.tm_hour = time->hours; tm.tm_hour = time_->hours;
tm.tm_min = time->minutes; tm.tm_min = time_->minutes;
tm.tm_sec = time->seconds; tm.tm_sec = time_->seconds;
time_t timestamp = timegm(&tm); time_t timestamp = timegm(&tm);
if (timestamp != -1) { if (timestamp != -1) {
tv->tv_sec = timestamp; tv->tv_sec = timestamp;
tv->tv_usec = time->microseconds; tv->tv_usec = time_->microseconds;
return 0; return 0;
} else { } else {
return -1; return -1;

View File

@ -182,7 +182,7 @@ bool minmea_parse_gsv(struct minmea_sentence_gsv *frame, const char *sentence);
/** /**
* Convert GPS UTC date/time representation to a UNIX timestamp. * Convert GPS UTC date/time representation to a UNIX timestamp.
*/ */
int minmea_gettimeofday(struct timeval *tv, const struct minmea_date *date, const struct minmea_time *time); int minmea_gettimeofday(struct timeval *tv, const struct minmea_date *date, const struct minmea_time *time_);
/** /**
* Rescale a fixed-point value to a different scale. Rounds towards zero. * Rescale a fixed-point value to a different scale. Rounds towards zero.

78
tests.c
View File

@ -268,28 +268,28 @@ END_TEST
START_TEST(test_minmea_scan_T) START_TEST(test_minmea_scan_T)
{ {
struct minmea_time time; struct minmea_time time_;
ck_assert(minmea_scan("$GPXXX,2359", "_T", &time) == false); ck_assert(minmea_scan("$GPXXX,2359", "_T", &time_) == false);
ck_assert(minmea_scan("$GPXXX,foobar", "_T", &time) == false); ck_assert(minmea_scan("$GPXXX,foobar", "_T", &time_) == false);
ck_assert(minmea_scan("$GPXXX,235960", "_T", &time) == true); ck_assert(minmea_scan("$GPXXX,235960", "_T", &time_) == true);
ck_assert_int_eq(time.hours, 23); ck_assert_int_eq(time_.hours, 23);
ck_assert_int_eq(time.minutes, 59); ck_assert_int_eq(time_.minutes, 59);
ck_assert_int_eq(time.seconds, 60); ck_assert_int_eq(time_.seconds, 60);
ck_assert_int_eq(time.microseconds, 0); ck_assert_int_eq(time_.microseconds, 0);
ck_assert(minmea_scan("$GPXXX,213700.001", "_T", &time) == true); ck_assert(minmea_scan("$GPXXX,213700.001", "_T", &time_) == true);
ck_assert_int_eq(time.hours, 21); ck_assert_int_eq(time_.hours, 21);
ck_assert_int_eq(time.minutes, 37); ck_assert_int_eq(time_.minutes, 37);
ck_assert_int_eq(time.seconds, 0); ck_assert_int_eq(time_.seconds, 0);
ck_assert_int_eq(time.microseconds, 1000); ck_assert_int_eq(time_.microseconds, 1000);
ck_assert(minmea_scan("$GPXXX,,,,,,,nope", "_T", &time) == true); ck_assert(minmea_scan("$GPXXX,,,,,,,nope", "_T", &time_) == true);
ck_assert_int_eq(time.hours, -1); ck_assert_int_eq(time_.hours, -1);
ck_assert_int_eq(time.minutes, -1); ck_assert_int_eq(time_.minutes, -1);
ck_assert_int_eq(time.seconds, -1); ck_assert_int_eq(time_.seconds, -1);
ck_assert_int_eq(time.microseconds, -1); ck_assert_int_eq(time_.microseconds, -1);
} }
END_TEST END_TEST
@ -297,7 +297,7 @@ START_TEST(test_minmea_scan_complex1)
{ {
const char *sentence = "$GPGGA,123519,4807.038,N,01131.000,E,1,08,0.9,545.4,M,46.9,M,,*47\r\n"; const char *sentence = "$GPGGA,123519,4807.038,N,01131.000,E,1,08,0.9,545.4,M,46.9,M,,*47\r\n";
char type[6]; char type[6];
struct minmea_time time; struct minmea_time time_;
struct minmea_float latitude; int latitude_direction; struct minmea_float latitude; int latitude_direction;
struct minmea_float longitude; int longitude_direction; struct minmea_float longitude; int longitude_direction;
int fix_quality; int fix_quality;
@ -307,7 +307,7 @@ START_TEST(test_minmea_scan_complex1)
struct minmea_float height; char height_units; struct minmea_float height; char height_units;
ck_assert(minmea_scan(sentence, "tTfdfdiiffcfc__", ck_assert(minmea_scan(sentence, "tTfdfdiiffcfc__",
type, type,
&time, &time_,
&latitude, &latitude_direction, &latitude, &latitude_direction,
&longitude, &longitude_direction, &longitude, &longitude_direction,
&fix_quality, &fix_quality,
@ -316,9 +316,9 @@ START_TEST(test_minmea_scan_complex1)
&altitude, &altitude_units, &altitude, &altitude_units,
&height, &height_units) == true); &height, &height_units) == true);
ck_assert_str_eq(type, "GPGGA"); ck_assert_str_eq(type, "GPGGA");
ck_assert_int_eq(time.hours, 12); ck_assert_int_eq(time_.hours, 12);
ck_assert_int_eq(time.minutes, 35); ck_assert_int_eq(time_.minutes, 35);
ck_assert_int_eq(time.seconds, 19); ck_assert_int_eq(time_.seconds, 19);
ck_assert_int_eq(latitude.value, 4807038); ck_assert_int_eq(latitude.value, 4807038);
ck_assert_int_eq(latitude.scale, 1000); ck_assert_int_eq(latitude.scale, 1000);
ck_assert_int_eq(latitude_direction, 1); ck_assert_int_eq(latitude_direction, 1);
@ -343,7 +343,7 @@ START_TEST(test_minmea_scan_complex2)
{ {
const char *sentence = "$GPBWC,081837,,,,,,T,,M,,N,*13"; const char *sentence = "$GPBWC,081837,,,,,,T,,M,,N,*13";
char type[6]; char type[6];
struct minmea_time time; struct minmea_time time_;
struct minmea_float latitude; int latitude_direction; struct minmea_float latitude; int latitude_direction;
struct minmea_float longitude; int longitude_direction; struct minmea_float longitude; int longitude_direction;
struct minmea_float bearing_true; char bearing_true_mark; struct minmea_float bearing_true; char bearing_true_mark;
@ -352,7 +352,7 @@ START_TEST(test_minmea_scan_complex2)
char name[MINMEA_MAX_LENGTH]; char name[MINMEA_MAX_LENGTH];
ck_assert(minmea_scan(sentence, "tTfdfdfcfcfcs", ck_assert(minmea_scan(sentence, "tTfdfdfcfcfcs",
type, type,
&time, &time_,
&latitude, &latitude_direction, &latitude, &latitude_direction,
&longitude, &longitude_direction, &longitude, &longitude_direction,
&bearing_true, &bearing_true_mark, &bearing_true, &bearing_true_mark,
@ -360,9 +360,9 @@ START_TEST(test_minmea_scan_complex2)
&distance, &distance_units, &distance, &distance_units,
name) == true); name) == true);
ck_assert_str_eq(type, "GPBWC"); ck_assert_str_eq(type, "GPBWC");
ck_assert_int_eq(time.hours, 8); ck_assert_int_eq(time_.hours, 8);
ck_assert_int_eq(time.minutes, 18); ck_assert_int_eq(time_.minutes, 18);
ck_assert_int_eq(time.seconds, 37); ck_assert_int_eq(time_.seconds, 37);
ck_assert_int_eq(latitude.scale, 0); ck_assert_int_eq(latitude.scale, 0);
ck_assert_int_eq(latitude_direction, 0); ck_assert_int_eq(latitude_direction, 0);
ck_assert_int_eq(longitude.scale, 0); ck_assert_int_eq(longitude.scale, 0);
@ -381,7 +381,7 @@ START_TEST(test_minmea_scan_complex3)
{ {
const char *sentence = "$GPGST,024603.00,3.2,6.6,4.7,47.3,5.8,5.6,22.0*58"; const char *sentence = "$GPGST,024603.00,3.2,6.6,4.7,47.3,5.8,5.6,22.0*58";
char type[6]; char type[6];
struct minmea_time time; struct minmea_time time_;
struct minmea_float rms_deviation; struct minmea_float rms_deviation;
struct minmea_float semi_major_deviation; struct minmea_float semi_major_deviation;
struct minmea_float semi_minor_deviation; struct minmea_float semi_minor_deviation;
@ -391,7 +391,7 @@ START_TEST(test_minmea_scan_complex3)
struct minmea_float altitude_error_deviation; struct minmea_float altitude_error_deviation;
ck_assert(minmea_scan(sentence, "tTfffffff", ck_assert(minmea_scan(sentence, "tTfffffff",
type, type,
&time, &time_,
&rms_deviation, &rms_deviation,
&semi_major_deviation, &semi_major_deviation,
&semi_minor_deviation, &semi_minor_deviation,
@ -400,10 +400,10 @@ START_TEST(test_minmea_scan_complex3)
&longitude_error_deviation, &longitude_error_deviation,
&altitude_error_deviation) == true); &altitude_error_deviation) == true);
ck_assert_str_eq(type, "GPGST"); ck_assert_str_eq(type, "GPGST");
ck_assert_int_eq(time.hours, 2); ck_assert_int_eq(time_.hours, 2);
ck_assert_int_eq(time.minutes, 46); ck_assert_int_eq(time_.minutes, 46);
ck_assert_int_eq(time.seconds, 3); ck_assert_int_eq(time_.seconds, 3);
ck_assert_int_eq(time.microseconds, 0); ck_assert_int_eq(time_.microseconds, 0);
ck_assert_int_eq(rms_deviation.value, 32); ck_assert_int_eq(rms_deviation.value, 32);
ck_assert_int_eq(rms_deviation.scale, 10); ck_assert_int_eq(rms_deviation.scale, 10);
ck_assert_int_eq(semi_major_deviation.value, 66); ck_assert_int_eq(semi_major_deviation.value, 66);
@ -649,18 +649,18 @@ END_TEST
START_TEST(test_minmea_gettimeofday) START_TEST(test_minmea_gettimeofday)
{ {
struct minmea_date date = { 14, 2, 14 }; struct minmea_date date = { 14, 2, 14 };
struct minmea_time time = { 13, 0, 9, 123456 }; struct minmea_time time_ = { 13, 0, 9, 123456 };
struct timeval tv; struct timeval tv;
ck_assert(minmea_gettimeofday(&tv, &date, &time) == 0); ck_assert(minmea_gettimeofday(&tv, &date, &time_) == 0);
ck_assert_int_eq(tv.tv_sec, 1392382809); ck_assert_int_eq(tv.tv_sec, 1392382809);
ck_assert_int_eq(tv.tv_usec, 123456); ck_assert_int_eq(tv.tv_usec, 123456);
date.year = -1; date.year = -1;
ck_assert(minmea_gettimeofday(&tv, &date, &time) != 0); ck_assert(minmea_gettimeofday(&tv, &date, &time_) != 0);
date.year = 2014; date.year = 2014;
time.hours = -1; time_.hours = -1;
ck_assert(minmea_gettimeofday(&tv, &date, &time) != 0); ck_assert(minmea_gettimeofday(&tv, &date, &time_) != 0);
} }
END_TEST END_TEST