LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 725|回复: 3

gcc不能在函数里面调用其他函数吗?

[复制链接]
发表于 2010-12-3 13:36:05 | 显示全部楼层 |阅读模式
直接上测试代码
  1. #include <stdio.h>
  2.   2 #include <stdlib.h>
  3.   3 int main(void)
  4.   4 {
  5.   5     void swap (int *a, int *b);
  6.   6     void bbb(void);
  7.   7     int a=2;
  8.   8     int c=3;
  9.   9     swap (&a, &c);
  10. 10     return 0;
  11. 11 }
  12. 12 void bbb(void)
  13. 13 {
  14. 14     int a=2;
  15. 15     int b=3;
  16. 16     swap (&a, &b);
  17. 17 }
  18. 18 void swap (int *a, int *b)
  19. 19 {   
  20. 20     *a ^= *b;
  21. 21     *b ^= *a;
  22. 22     *a ^= *b;
  23. 23 }
  24. ~      
复制代码

gcc报错
  1. gcc test.c
  2. test.c: In function ‘bbb’:
  3. test.c:16: error: incompatible implicit declaration of function ‘swap’
  4. test.c:5: note: previous implicit declaration of ‘swap’ was here

复制代码
发表于 2010-12-3 14:53:30 | 显示全部楼层
能阿,不过不支持在一个函数里申明另一个函数
回复 支持 反对

使用道具 举报

发表于 2010-12-3 15:28:15 | 显示全部楼层
bbb函数中没有声明swap。
回复 支持 反对

使用道具 举报

 楼主| 发表于 2010-12-3 23:19:43 | 显示全部楼层
拜谢楼上的。
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表