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

我可以想訪問地址零嗎?

Could I ever want to access the address zero?(我可以想訪問地址零嗎?)
本文介紹了我可以想訪問地址零嗎?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

限時送ChatGPT賬號..

常量 0 在 C 和 C++ 中用作空指針.但正如問題指向特定固定地址的指針" 似乎可以使用分配固定地址.在任何系統中,對于訪問地址 0 的任何低級任務,是否有任何可想象的需求?

The constant 0 is used as the null pointer in C and C++. But as in the question "Pointer to a specific fixed address" there seems to be some possible use of assigning fixed addresses. Is there ever any conceivable need, in any system, for whatever low level task, for accessing the address 0?

如果有,如何用 0 為空指針和所有來解決?

If there is, how is that solved with 0 being the null pointer and all?

如果不是,那么是什么確定沒有這種需要?

If not, what makes it certain that there is not such a need?

推薦答案

無論是在 C 中還是在 C++ 中,空指針值都與物理地址 0 沒有任何關聯.您在源代碼中使用常量0 來設置指向空指針值的指針,這只不過是一個語法糖.編譯器需要將其轉換為特定平臺上用作空指針值的實際物理地址.

Neither in C nor in C++ null-pointer value is in any way tied to physical address 0. The fact that you use constant 0 in the source code to set a pointer to null-pointer value is nothing more than just a piece of syntactic sugar. The compiler is required to translate it into the actual physical address used as null-pointer value on the specific platform.

換句話說,源代碼中的 0 沒有任何物理重要性.例如,它可能是 4213.IE.語言作者,如果他們愿意的話,可以這樣做,這樣你就必須執行 p = 42 以便將指針 p 設置為空指針值.同樣,這并不意味著必須為空指針保留物理地址 42.編譯器需要將源代碼 p = 42 翻譯成機器代碼,這些機器代碼將填充實際的物理空指針值(0x00000xBAAD) 進入指針 p.這正是使用常量 0 時的情況.

In other words, 0 in the source code has no physical importance whatsoever. It could have been 42 or 13, for example. I.e. the language authors, if they so pleased, could have made it so that you'd have to do p = 42 in order to set the pointer p to null-pointer value. Again, this does not mean that the physical address 42 would have to be reserved for null pointers. The compiler would be required to translate source code p = 42 into machine code that would stuff the actual physical null-pointer value (0x0000 or 0xBAAD) into the pointer p. That's exactly how it is now with constant 0.

另請注意,C 和 C++ 都沒有提供嚴格定義的功能,允許您將特定的物理地址分配給指針.因此,您關于如何將 0 地址分配給指針"的問題正式沒有答案.您根本無法為 C/C++ 中的指針分配特定地址.但是,在實現定義的功能領域,顯式整數到指針的轉換旨在產生這種效果.所以,你會這樣做

Also note, that neither C nor C++ provides a strictly defined feature that would allow you to assign a specific physical address to a pointer. So your question about "how one would assign 0 address to a pointer" formally has no answer. You simply can't assign a specific address to a pointer in C/C++. However, in the realm of implementation-defined features, the explicit integer-to-pointer conversion is intended to have that effect. So, you'd do it as follows

uintptr_t address = 0;
void *p = (void *) address;

注意,這和做不一樣

void *p = 0;

后者總是產生空指針值,而前者在一般情況下不會.前者通常會產生一個指向物理地址 0 的指針,它可能是也可能不是給定平臺上的空指針值.

The latter always produces the null-pointer value, while the former in general case does not. The former will normally produce a pointer to physical address 0, which might or might not be the null-pointer value on the given platform.

這篇關于我可以想訪問地址零嗎?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

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

相關文檔推薦

Difference between std::reference_wrapper and simple pointer?(std::reference_wrapper 和簡單指針的區別?)
Difference between const. pointer and reference?(常量之間的區別.指針和引用?)
How to access the contents of a vector from a pointer to the vector in C++?(c++ - 如何從指向向量的指針訪問向量的內容?)
Meaning of *amp; and **amp; in C++(*amp; 的含義和**amp;在 C++ 中)
Why can#39;t I do polymorphism with normal variables?(為什么我不能對普通變量進行多態?)
Dereferencing deleted pointers always result in an Access Violation?(取消引用已刪除的指針總是會導致訪問沖突?)
主站蜘蛛池模板: 麻豆久久久久久 | 日韩免费网站 | 国产精品三级 | 一区视频在线免费观看 | 华丽的挑战在线观看 | 国产欧美精品一区 | 99热这里只有精品8 激情毛片 | 久久久99国产精品免费 | 日韩一二三 | 亚洲成人在线免费 | 男人久久天堂 | 亚洲天堂中文字幕 | 久久亚洲国产精品日日av夜夜 | 爱爱无遮挡 | 91天堂网| 一区二区三区在线播放视频 | 久久久久国产 | 国产精品久久久久永久免费观看 | 激情国产| 国产午夜影院 | 国产高清在线观看 | 亚洲一区中文字幕 | 午夜影院在线观看 | 国产ts人妖一区二区三区 | 欧洲精品一区 | 久久久久一区 | 亚洲欧美中文日韩在线v日本 | 久久最新网址 | 欧美一级做性受免费大片免费 | 成年人在线视频 | 久草在线视频中文 | 黄视频免费 | 很黄很污的网站 | 精品美女在线观看视频在线观看 | 亚洲精品中文字幕在线 | 国产欧美在线观看 | 中文字幕一区二区三区四区 | 国产午夜三级一区二区三 | 精品国产免费人成在线观看 | 91精品一区二区三区久久久久久 | 午夜av电影 |