|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
在main函数中声明的max函数,在test()函数中可不可以不声明直接调用,还是说这个看编译器?
- #include <stdio.h>
- int test();
- void main()
- {
- float max(float x, float y);
- float a,b;
- scanf("%f,%f",&a,&b);
- printf("%f",max(a,b));
- test();
- }
- int test()
- {
- float a=1,b=2;
- float c;
- c=max(a,b);
- printf("Max is %f\n",c);
- return 0;
- }
- float max(float x, float y)
- { float z;
- z=x>y?x:y;
- return z;
- }
复制代码
本帖最后由 jackz007 于 2022-11-15 22:32 编辑
确实,VC都可以,但是 gcc 不灵
【tdm-gcc 5.1.0】:
- D:\[00.Exerciese.2022]\C>g++ -o x x.c
- x.c:3:11: error: '::main' must return 'int'
- void main()
- ^
- x.c: In function 'int test()':
- x.c:15:18: error: 'max' was not declared in this scope
- c=max(a,b);
- ^
- D:\[00.Exerciese.2022]\C>
复制代码
【vc6.0】:
- D:\[00.Exerciese.2022]\C>cl x.c
- Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 12.00.8804 for 80x86
- Copyright (C) Microsoft Corp 1984-1998. All rights reserved.
- x.c
- Microsoft (R) Incremental Linker Version 6.00.8447
- Copyright (C) Microsoft Corp 1992-1998. All rights reserved.
- /out:x.exe
- x.obj
- D:\[00.Exerciese.2022]\C>
复制代码
【vc9.0】:
- D:\[00.Exerciese.2022]\C>cl x.c
- 用于 80x86 的 Microsoft (R) 32 位 C/C++ 优化编译器 15.00.30729.01 版
- 版权所有(C) Microsoft Corporation。保留所有权利。
- x.c
- Microsoft (R) Incremental Linker Version 9.00.30729.01
- Copyright (C) Microsoft Corporation. All rights reserved.
- /out:x.exe
- x.obj
- D:\[00.Exerciese.2022]\C>
复制代码
|
|