是的,以前有人问过,我已经听从了这里的建议,把我的声明放在最上面仍然没有用。
void map_delete(map_t *map, char *key) {
assert(map_contains(map, key));
map_elem_t *prev;
map_elem_t *elem_to_remove;
prev = map->elem;
while(strcmp(prev->next->key, key) != 0) prev= prev->next;
elem_to_remove = prev->next;
prev->next = elem_to_remove->next;
free(elem_to_remove);
}
map.c(74): error C2143: syntax error : missing ';' before 'type'
map.c(76): error C2065: 'prev' : undeclared identifier
map.c(76): warning C4047: '=' : 'int' differs in levels of indirection from 'map_elem_t *'
map.c(77): error C2065: 'prev' : undeclared identifier
map.c(77): error C2223: left of '->next' must point to struct/union
map.c(77): error C2198: 'strcmp' : too few arguments for call
map.c(77): error C2065: 'prev' : undeclared identifier
map.c(77): error C2065: 'prev' : undeclared identifier
map.c(77): error C2223: left of '->next' must point to struct/union
map.c(79): error C2065: 'elem_to_remove' : undeclared identifier
map.c(79): error C2065: 'prev' : undeclared identifier
map.c(79): error C2223: left of '->next' must point to struct/union
map.c(80): error C2065: 'prev' : undeclared identifier
map.c(80): error C2223: left of '->next' must point to struct/union
map.c(80): error C2065: 'elem_to_remove' : undeclared identifier
map.c(80): error C2223: left of '->next' must point to struct/union
map.c(81): error C2065: 'elem_to_remove' : undeclared identifier
map.c(81): warning C4022: 'free' : pointer mismatch for actual parameter 1
注意代码的逻辑是正确的,因为它在另一台机器上工作,它的编译器对布局不满意