未定义的行为 [英] Undefined behaviour

查看:93
本文介绍了未定义的行为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我听到很多关于未定义的行为的消息。在这个和其他新闻组中

处理c / c ++。


是否列出了列出C ++中未定义行为的所有案例?


关于marbac

Hi,

i heard a lot about "undefined behaviour" in this and other newsgroups
dealing with c/c++.

Is there a list where all cases with undefined behaviour in C++ are listed?

regards marbac

推荐答案



" marbac" <毫安**** @ chello.at>在留言中写道

news:qh ****************** @ news.chello.at ...

"marbac" <ma****@chello.at> wrote in message
news:qh******************@news.chello.at...
你好,
我听到很多关于未定义的行为的消息。在这个和其他新闻组中处理c / c ++。

是否列出了所有在C ++中具有未定义行为的情况
Hi,

i heard a lot about "undefined behaviour" in this and other newsgroups
dealing with c/c++.

Is there a list where all cases with undefined behaviour in C++ are



列出的情况?


我不知道任何编译为列表。

但是阅读神圣标准,它说明了未定义的行为。


-Sharad


listed?

I don''t know of any compiled as a list.
But read the Holy Standard, it speaks a lot about undefined behaviors.

-Sharad




" marbac" <毫安**** @ chello.at>在留言中写道

news:qh ****************** @ news.chello.at ...

"marbac" <ma****@chello.at> wrote in message
news:qh******************@news.chello.at...
你好,
我听到很多关于未定义的行为的消息。在这个和其他新闻组中处理c / c ++。

是否列出了C ++中所有未定义行为的案例都列出了

关于marbac
Hi,

i heard a lot about "undefined behaviour" in this and other newsgroups
dealing with c/c++.

Is there a list where all cases with undefined behaviour in C++ are listed?
regards marbac




它被称为C ++标准,长达数百页。


我最喜欢的是导致未定义行为的几个常见原因


1)取消引用空指针

2)访问数组边界外

3)删除相同的内存两次

4)在删除指针后取消引用指针

5)取消引用指向被破坏对象的指针

6)访问未初始化的变量

7)签名整数溢出

8)修改const对象


毫无疑问我'错过了很多其他人


正如你所看到的,未定义行为的几个常见原因涉及

指针。因此道德不是指针,而是更喜欢STL课程,

它们更安全一些。


john



It''s called the C++ standard, and its several hundred pages long.

Off the top of my head here are a few common causes of undefined behaviour

1) dereferencing a null pointer
2) accessing outside the bounds of an array
3) deleting the same memory twice
4) dereferencing a pointer after it has been deleted
5) dereferencing a pointer which points to a destroyed object
6) accessing an uninitialised variable
7) signed integer overflow
8) modifying a const object

No doubt I''ve missed many others

As you can see several of the common causes of undefined behaviour involve
pointers. So the moral is don''t use pointers, prefer STL classes instead,
they are somewhat safer.

john




" John Harrison" <乔************* @ hotmail.com>在消息中写道

新闻:2l ************ @ uni-berlin.de ...

"John Harrison" <jo*************@hotmail.com> wrote in message
news:2l************@uni-berlin.de...

marbac ; <毫安**** @ chello.at>在消息中写道
新闻:qh ****************** @ news.chello.at ...

"marbac" <ma****@chello.at> wrote in message
news:qh******************@news.chello.at...

我听到很多关于未定义的行为的消息。在这个和其他新闻组处理c / c ++。

是否列出了C ++中未定义行为的所有案例
Hi,

i heard a lot about "undefined behaviour" in this and other newsgroups
dealing with c/c++.

Is there a list where all cases with undefined behaviour in C++ are



关于marbac

regards marbac



它被称为C ++标准,长达数百页。

我的头脑是一些未定义行为的常见原因

1)取消引用空指针
2)访问数组范围外的内容
3)删除相同的内存两次< br)在删除指针后取消引用指针
5)取消引用指向被破坏对象的指针
6)访问未初始化的变量
7)有符号整数溢出 > 8)修改一个const对象



It''s called the C++ standard, and its several hundred pages long.

Off the top of my head here are a few common causes of undefined behaviour

1) dereferencing a null pointer
2) accessing outside the bounds of an array
3) deleting the same memory twice
4) dereferencing a pointer after it has been deleted
5) dereferencing a pointer which points to a destroyed object
6) accessing an uninitialised variable
7) signed integer overflow
8) modifying a const object




多一些打击我 -

1)主要返回无效

2 )删除指针后复制指针

3)使用不匹配的新/删除数组形式

4)Modifyin ga string literal

5)在没有序列点的情况下更改变量两次

6)使用auto_ptr实例化STL容器

7)添加声明/ std命名空间的定义

8)玩reinterpret_cast


更多...


-Sharad



Some more strike me -
1) main returning void
2) Copying a pointer after it has been deleted
3) Using mismatched forms of new/delete for arrays
4) Modifying a string literal
5) Changing a variable twice without a sequence point
6) Instantiating an STL container with auto_ptr
7) Adding declarations/definitions to std namespace
8) Playing around with reinterpret_cast

many more...

-Sharad


这篇关于未定义的行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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