【问题标题】:Syntax error : missing ';' before 'type' C code语法错误:缺少';'在“输入”C 代码之前
【发布时间】:2013-07-18 13:24:02
【问题描述】:

是的,之前有人问过这个问题,我已经听从了here 的建议,并将我的声明放在顶部仍然不起作用。

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

注意代码的逻辑是正确的,因为它在另一台机器上工作,它的编译器对布局不满意

【问题讨论】:

  • assert(map_contains(map, key)); 不是声明。 (获得一个支持更合理的 C 标准的编译器并不是一个坏主意。)
  • 谢谢,我希望我也可以,告诉我的老板! :(

标签: c compiler-construction error-handling


【解决方案1】:

编译器抱怨因为assert 不是声明。您需要将assert 移动到声明之后。

使用支持 C89 的较新标准的 C 编译器将是一个不错的举措。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-12-01
    • 2019-07-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多