我有以下代码段,在编译时会发出警告(代码仍然有效):
char *x_first_name, *x_last_name, *x_address, *x_zip;
const size_t firsts_count = sizeof(firsts) / sizeof(firsts[0]);
const size_t lasts_count = sizeof(lasts) / sizeof(lasts[0]);
const size_t streets_count = sizeof(streets) / sizeof(streets[0]);
const size_t zips_count = sizeof(zips) / sizeof(zips[0]);
srand(time(NULL));
x_first_name = firsts[rand() % firsts_count]; // line 69
x_last_name = lasts[rand() % lasts_count]; // line 70
x_address = streets[rand() % streets_count]; // line 71
x_zip = zips[rand() % zips_count]; // line 72
警告编译:
authorize.c: In function 'main':
authorize.c:69: warning: assignment discards qualifiers from pointer target type
authorize.c:70: warning: assignment discards qualifiers from pointer target type
authorize.c:71: warning: assignment discards qualifiers from pointer target type
authorize.c:72: warning: assignment discards qualifiers from pointer target type
firsts、lasts、streets 和 zips 声明为:
const char *firsts[] = {
"Asgar",
"Aadit",
"Aanand",
"Aaron"
};
我究竟做错了什么?