|
发表于 2021-10-16 11:30:45
|
显示全部楼层
此句用 gcc 10.2.0 编译出错
- int max(int a, int b, int c) return (a > b && a > c ? a : b > c ? b : c);
复制代码
具体信息为:
- D:\00.Excise\C>g++ -o x x.c
- x.c: In function 'int max(int, int, int)':
- x.c:3:37: error: expected identifier before '(' token
- 3 | int max(int a, int b, int c) return (a > b && a > c ? a : b > c ? b : c)
- ;
- | ^
- x.c:3:30: error: named return values are no longer supported
- 3 | int max(int a, int b, int c) return (a > b && a > c ? a : b > c ? b : c)
- ;
- | ^~~~~~
- x.c:6:9: error: declaration of 'int a' shadows a parameter
- 6 | int a, b, c;
- | ^
- x.c:3:13: note: 'int a' previously declared here
- 3 | int max(int a, int b, int c) return (a > b && a > c ? a : b > c ? b : c)
- ;
- | ~~~~^
- x.c:6:12: error: declaration of 'int b' shadows a parameter
- 6 | int a, b, c;
- | ^
- x.c:3:20: note: 'int b' previously declared here
- 3 | int max(int a, int b, int c) return (a > b && a > c ? a : b > c ? b : c)
- ;
- | ~~~~^
- x.c:6:15: error: declaration of 'int c' shadows a parameter
- 6 | int a, b, c;
- | ^
- x.c:3:27: note: 'int c' previously declared here
- 3 | int max(int a, int b, int c) return (a > b && a > c ? a : b > c ? b : c)
- ;
- | ~~~~^
- D:\00.Excise\C>
复制代码
必须改为
- int max(int a, int b, int c) {return (a > b && a > c ? a : b > c ? b : c);}
复制代码 |
|