这是VS 2005的Bug吗? [英] Is this a Bug of VS 2005?

查看:53
本文介绍了这是VS 2005的Bug吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是VS 2005的Bug吗?


我们知道size_t不是C ++中的内置数据类型,而只是一个

typedef声明。


但是,我发现以下代码通常可以用VS编译

2005:


//请注意,我不在此源文件中包含任何头文件


size_t测试(size_t a)

{

返回a;

}


int main()

{

size_t n =测试(8);


返回n;

}


为什么?这真的是VS 2005的错误吗?

Is this a Bug of VS 2005?

We know size_t is not a built-in data type in C++, rather, it is just a
typedef declaration.

However, I found the following code could be normally compiled with VS
2005:

// Note that I don''t include any header file in this source file

size_t Test(size_t a)
{
return a;
}

int main()
{
size_t n = Test(8);

return n;
}

Why? Is this really a bug of VS 2005?

推荐答案

2006年8月3日21:38:52 -0700,打火机 < cq **** @ gmail.comwrote

comp.lang.c ++:
On 3 Aug 2006 21:38:52 -0700, "Lighter" <cq****@gmail.comwrote in
comp.lang.c++:

这是VS 2005的Bug吗?
Is this a Bug of VS 2005?



No.

No.


我们知道size_t不是C ++中的内置数据类型,而是它只是一个

typedef声明。


但是,我发现以下代码通常可以用VS

2005编译:


//请注意,我不在此源文件中包含任何头文件


size_t Test(size_t a)

{

返回;

}


int main()

{

size_t n =测试(8);


返回n;

}


为什么?这真的是VS 2005的错误吗?
We know size_t is not a built-in data type in C++, rather, it is just a
typedef declaration.

However, I found the following code could be normally compiled with VS
2005:

// Note that I don''t include any header file in this source file

size_t Test(size_t a)
{
return a;
}

int main()
{
size_t n = Test(8);

return n;
}

Why? Is this really a bug of VS 2005?



它可以被视为一个扩展,并且扩展完全有效

,只要它们不影响严格符合的行为

计划。这不可能,因为该程序使用未定义的类型具有未定义的行为




此外,尝试通过添加某些内容来引发冲突喜欢:


typedef double size_t;


....在您的源文件中会导致更多未定义的行为,因为所有

typedef'继承自C库,包括size_t,是在全局和std命名空间中为编译器保留的。


-

Jack Klein

主页: http: //JK-Technology.Com

常见问题解答

comp.lang.c http://c-faq.com/

comp.lang.c ++ http://www.parashift.com/c++-faq-lite/

alt .comp.lang.learn.c-c ++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html

It can be considered an extension, and extensions are perfectly valid
as long as they do not affect the behavior of a strictly conforming
program. And this can''t, because the program has undefined behavior
by using an undefined type.

Furthermore, an attempt to cause a conflict by adding something like:

typedef double size_t;

....in your source file causes even more undefined behavior because all
typedef''s inherited from the C library, which includes size_t, are
reserved for the compiler in both the global and std namespaces.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://c-faq.com/
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html


给Jack Klein:


谢谢你的回答。但是,我不认为这是由VS 2005制作的C ++的扩展

。原因是VS 2005仍然可以正确编译上面的代码 - 甚至我设置了编译器

选项/ Za。

to Jack Klein:

Thank you for your answer. However, I don''t think this is an extension
for C++ made by VS 2005. The reason for this is that VS 2005 can still
correctly compile the code above-mentioned even I set the compiler
option /Za.




打火机??? é?????

Lighter ???é?????

这是VS 2005的Bug吗?


我们知道size_t不是内置的在C ++中的数据类型中,它只是一个

typedef声明。


然而,我发现以下代码通常可以用VS
2005:


//请注意,我不在此源文件中包含任何头文件


size_t测试(size_t a)

{

返回a;

}


int main()

{

size_t n =测试(8);


返回n;

}


为什么?这真的是VS 2005的错误吗?
Is this a Bug of VS 2005?

We know size_t is not a built-in data type in C++, rather, it is just a
typedef declaration.

However, I found the following code could be normally compiled with VS
2005:

// Note that I don''t include any header file in this source file

size_t Test(size_t a)
{
return a;
}

int main()
{
size_t n = Test(8);

return n;
}

Why? Is this really a bug of VS 2005?




一些头文件是默认包含。



Some "Header Files" is Default Includes.


这篇关于这是VS 2005的Bug吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆