okokpypy 发表于 2020-07-03 09:50

int a, float b; //为什么不报错??输出结果还不同?

int a, float b;             //为什么不报错??输出结果还不同?
   int c; float d;
   a = 0; b = 3.14;
      c = 0; d = 3.14;
   cout << a << " " << b << endl;
   cout << c << " " << d << endl;

bruceteen 发表于 2020-07-06 10:06

你用的是什么编译器?

#include <iostream>
using namespace std;

int main( void )
{
        int a, float b;
        int c; float d;
        a = 0; b = 3.14;
        c = 0; d = 3.14;
        cout << a << " " << b << endl;
        cout << c << " " << d << endl;
}
g++(测试用的是10.1.0版本)报错;
clang(测试用的是10.0.0版本)报错;
VC++(测试用的是16.6.2版本)报错。

bruceteen 发表于 2020-07-06 10:06

你用的是什么编译器?
gcc、clang、vc++ 我都测试过了,都报错。

bruceteen 发表于 2020-07-06 10:07

没法回帖?

okokpypy 发表于 2020-07-06 12:10

回复 4# bruceteen

vc 6.0 这不是通用的教学编译器么?

ichao1214 发表于 2020-07-11 13:26

实测vc6.0编译结果如下:
warning C4518: 'float ' : storage-class or type specifier(s) unexpected here; ignored
warning C4228: nonstandard extension used : qualifiers after comma in declarator list are ignored
warning C4305: '=' : truncation from 'const double' to 'float'


关键在C4228,去微软官网查,b前面的float被忽略了,当成了int。

ichao1214 发表于 2020-07-11 13:27

实测vc6.0编译结果如下:
warning C4518: 'float ' : storage-class or type specifier(s) unexpected here; ignored
warning C4228: nonstandard extension used : qualifiers after comma in declarator list are ignored
warning C4305: '=' : truncation from 'const double' to 'float'


关键在C4228,去微软官网查,b前面的float被忽略了,当成了int。

ichao1214 发表于 2020-07-11 13:30

实测vc6.0编译结果如下:
warning C4518: 'float ' : storage-class or type specifier(s) unexpected here; ignored
warning C4228: nonstandard extension used : qualifiers after comma in declarator list are ignored
warning C4305: '=' : truncation from 'const double' to 'float'


关键在C4228,去微软官网查,b前面的float被忽略了,当成了int。

ichao1214 发表于 2020-07-11 13:35

warning C4518: 'float ' : storage-class or type specifier(s) unexpected here; ignored
warning C4228: nonstandard extension used : qualifiers after comma in declarator list are ignored
warning C4305: '=' : truncation from 'const double' to 'float'
C4288 去查一下

ichao1214 发表于 2020-07-11 13:36

warning C4518: 'float ' : storage-class or type specifier(s) unexpected here; ignored
warning C4228: nonstandard extension used : qualifiers after comma in declarator list are ignored
warning C4305: '=' : truncation from 'const double' to 'float'
页: [1] 2
查看完整版本: int a, float b; //为什么不报错??输出结果还不同?