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

指針變量只是帶有某些運算符的整數還是“符號

Are pointer variables just integers with some operators or are they quot;symbolicquot;?(指針變量只是帶有某些運算符的整數還是“符號?)
本文介紹了指針變量只是帶有某些運算符的整數還是“符號"?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

限時送ChatGPT賬號..

原始單詞選擇令人困惑.象征"一詞比原來的(神秘")好得多.

The original word choice was confusing. The term "symbolic" is much better than the original ("mystical").

在關于我之前的 C++ 問題的討論中,我被告知指針是

In the discussion about my previous C++ question, I have been told that pointers are

  • "一個很像的簡單值類型一個整數"
  • 不是神秘的"
  • "位模式(對象表示) 包含普通可復制類型的值(值表示)(第 3.9/4 節),這是一個指針."

這聽起來不對!如果沒有什么是象征性的并且指針是它的表示,那么我可以執行以下操作.我可以嗎?

This does not sound right! If nothing is symbolic and a pointer is its representation, then I can do the following. Can I?

#include <stdio.h>
#include <string.h>

int main() {
    int a[1] = { 0 }, *pa1 = &a[0] + 1, b = 1, *pb = &b;
    if (memcmp (&pa1, &pb, sizeof pa1) == 0) {
        printf ("pa1 == pb
");
        *pa1 = 2;
    }
    else {
        printf ("pa1 != pb
");
        pa1 = &a[0]; // ensure well defined behaviour in printf
    }
    printf ("b = %d *pa1 = %d
", b, *pa1);
    return 0;
 }

這是一個 C 和 C++ 問題.

This is a C and C++ question.

使用 在線編譯和執行 C 進行測試,使用 GNU GCC v4.8.3:gcc -O2 -Wall 給出

Testing with Compile and Execute C Online with GNU GCC v4.8.3: gcc -O2 -Wall gives

pa1 == pb                                                                                                                                                                                       
b = 1 *pa1 = 2    

使用 在線編譯和執行 C++ 進行測試,使用 GNU GCC v4.8.3:g++ -O2 -Wall

Testing with Compile and Execute C++ Online with GNU GCC v4.8.3: g++ -O2 -Wall

pa1 == pb                                                                                                                                                                                       
b = 1 *pa1 = 2        

所以通過(&a)[1]修改b失敗,在C和C++中使用GCC.

So the modification of b via (&a)[1] fails with GCC in C and C++.

當然,我想要一個基于標準引述的答案.

Of course, I would like an answer based on standard quotes.

為了回應對 &a + 1 上 UB 的批評,現在 a 是一個包含 1 個元素的數組.

To respond to criticism about UB on &a + 1, now a is an array of 1 element.

相關:解引用包含對象地址的越界指針(數組數組)

附加說明:我認為,神秘"一詞最初是由 Tony Delroy 此處.我借錯了.

Additional note: the term "mystical" was first used, I think, by Tony Delroy here. I was wrong to borrow it.

推薦答案

C 被認為是一種指針和整數密切相關的語言,確切的關系取決于目標平臺.指針和整數之間的關系使該語言非常適合用于低級或系統編程的目的.出于以下討論的目的,我將這種語言稱為低級 C"[LLC].

C was conceived as a language in which pointers and integers were very intimately related, with the exact relationship depending upon the target platform. The relationship between pointers and integers made the language very suitable for purposes of low-level or systems programming. For purposes of discussion below, I'll thus call this language "Low-Level C" [LLC].

C 標準委員會編寫了對不同語言的描述,其中沒有明確禁止這種關系,但不會以任何有用的方式承認,即使實現為目標生成代碼和應用領域,這種關系將是有用的.我將這種語言稱為僅高級 C"[HLOC].

The C Standards Committee wrote up a description of a different language, where such a relationship is not expressly forbidden, but is not acknowledged in any useful fashion, even when an implementation generates code for a target and application field where such a relationship would be useful. I'll call this language "High Level Only C" [HLOC].

在編寫標準的年代,大多數自稱為 C 實現的東西處理的是 LLC 的方言.大多數有用的編譯器處理一種方言,該方言在比 HLOC 更多的情況下定義了有用的語義,但沒有 LLC 那么多.指針的行為是更像整數還是更像抽象的神秘實體取決于人們使用的是哪種方言.如果正在進行系統編程,將 C 視為密切相關的指針和整數是合理的,因為適合該目的的 LLC 方言這樣做,而不這樣做的 HLOC 方言不適合該目的.然而,在進行高端數字運算時,人們往往會使用無法識別這種關系的 HLOC 方言.

In the days when the Standard was written, most things that called themselves C implementations processed a dialect of LLC. Most useful compilers process a dialect which defines useful semantics in more cases than HLOC, but not as many as LLC. Whether pointers behave more like integers or more like abstract mystical entities depends upon which exact dialect one is using. If one is doing systems programming, it is reasonable to view C as treating pointers and integers as intimately related, because LLC dialects suitable for that purpose do so, and HLOC dialects that don't do so aren't suitable for that purpose. When doing high-end number crunching, however, one would far more often being using dialects of HLOC which do not recognize such a relationship.

真正的問題和這么多爭論的根源在于,LLC 和 HLOC 的分歧越來越大,但它們都被稱為 C.

The real problem, and source of so much contention, lies in the fact that LLC and HLOC are increasingly divergent, and yet are both referred to by the name C.

這篇關于指針變量只是帶有某些運算符的整數還是“符號"?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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?(取消引用已刪除的指針總是會導致訪問沖突?)
主站蜘蛛池模板: 亚洲 欧美 日韩 在线 | 91色视频在线观看 | 99爱在线视频 | 在线免费看91 | 国产精品国产三级国产aⅴ原创 | 日韩精品免费在线观看 | 狠狠躁躁夜夜躁波多野结依 | 日韩中文字幕一区二区三区 | 久久久精| 成人国产免费视频 | 激情欧美一区二区三区 | 国产乱码精品一区二区三区中文 | 欧美激情免费在线 | 99爱在线免费观看 | 91欧美精品成人综合在线观看 | 粉嫩一区二区三区四区公司1 | www97影院| 中文字幕蜜臀av | 久久性色 | 欧一区二区 | 亚洲免费精品 | 怡红院怡春院一级毛片 | 欧美一级α片 | 麻豆视频国产在线观看 | 五月网婷婷 | 中文字幕国产精品视频 | 国产中文字幕网 | 亚洲视频中文字幕 | 日韩影音| 激情伊人网 | 国产精品一区二区三 | 伊人伊成久久人综合网站 | 中文字幕亚洲精品 | 欧美黑人激情 | 国产欧美精品一区二区三区 | 99色视频| 亚洲精彩视频在线观看 | 精品在线观看一区二区 | 久久精品国产精品青草 | 亚洲一区视频在线 | 中国黄色在线视频 |