久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

在什么時候取消引用空指針會變成未定義的行為

At what point does dereferencing the null pointer become undefined behavior?(在什么時候取消引用空指針會變成未定義的行為?)
本文介紹了在什么時候取消引用空指針會變成未定義的行為?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

如果我沒有真正訪問解引用的對象",解引用空指針是否仍然未定義?

If I don't actually access the dereferenced "object", is dereferencing the null pointer still undefined?

int* p = 0;
int& r = *p;    // undefined?
int* q = &*p;   // undefined?

一個稍微實際一點的例子:我可以取消引用空指針來區分重載嗎?

A slightly more practical example: can I dereference the null pointer to distinguish between overloads?

void foo(Bar&);
void foo(Baz&);

foo(*(Bar*)0);  // undefined?

<小時>

好的,根據標準,參考示例肯定是未定義的行為:


Okay, the reference examples are definitely undefined behavior according to the standard:

在定義良好的程序中不能存在空引用,因為創建這種引用的唯一方法是將它綁定到通過取消引用空指針獲得的對象",這會導致未定義的行為強>.

a null reference cannot exist in a well-defined program, because the only way to create such a reference would be to bind it to the "object" obtained by dereferencing a null pointer, which causes undefined behavior.

不幸的是,強調的部分是模棱兩可的.是 binding 部分導致了未定義的行為,還是 取消引用 部分就足夠了?

Unfortunately, the emphasized part is ambiguous. Is it the binding part that causes undefined behavior, or is the dereferencing part sufficient?

推薦答案

是的,它是未定義的行為,因為規范說左值指定一個對象或函數"(在第 3.10 條)并且它說 *-操作符[解引用]的結果是一個左值,引用表達式指向的對象或函數"(見第 5.3.1 節).

Yes it is undefined behavior, because the spec says that an "lvalue designates an object or function" (at clause 3.10) and it says for the *-operator "the result [of dereferencing] is an lvalue referring to the object or function to which the expression points" (at clause 5.3.1).

這意味著沒有描述取消引用空指針時會發生什么.這只是未定義的行為.

That means there is no description for what happens when you dereference a null pointer. It's simply undefined behavior.

這篇關于在什么時候取消引用空指針會變成未定義的行為?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

What do compilers do with compile-time branching?(編譯器如何處理編譯時分支?)
Can I use if (pointer) instead of if (pointer != NULL)?(我可以使用 if (pointer) 而不是 if (pointer != NULL) 嗎?)
Checking for NULL pointer in C/C++(在 C/C++ 中檢查空指針)
Math-like chaining of the comparison operator - as in, quot;if ( (5lt;jlt;=1) )quot;(比較運算符的數學式鏈接-如“if((5<j<=1)))
Difference between quot;if constexpr()quot; Vs quot;if()quot;(“if constexpr()之間的區別與“if())
C++, variable declaration in #39;if#39; expression(C++,if 表達式中的變量聲明)
主站蜘蛛池模板: 亚洲黄色视屏 | 在线看av网址 | 91免费观看 | 国产欧美日韩综合精品一区二区 | 精品欧美在线观看 | 免费av观看 | 欧美色性| 在线观看国产wwwa级羞羞视频 | 人人做人人澡人人爽欧美 | 欧美成人一区二区三区片免费 | 欧美黑人一级爽快片淫片高清 | 亚洲色图综合 | 国产一区免费视频 | 国产精品视频区 | 欧美精品久久久久久久久老牛影院 | 欧美极品在线播放 | 91精品国产91久久久久久吃药 | 国产视频一区在线观看 | 精品国产一区二区三区久久影院 | 日韩国产专区 | 日韩黄色av | 国产精品亚洲第一 | 精品国产区 | 久久久精品视频免费看 | 国产精品久久国产精品 | 亚洲国产精品99久久久久久久久 | 91免费视频观看 | 久久久精品 | 久久33| 最新超碰 | 国产精品久久久久aaaa樱花 | 狠狠伊人 | h片免费在线观看 | 日韩中文字幕 | 久热精品免费 | 中文字幕一区在线 | 视频一二区 | 亚洲一区二区免费电影 | 亚洲色欲色欲www | 欧美一区二区另类 | 欧美电影在线观看网站 |