最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

詳談signed 關鍵字

 更新時間:2015年01月20日 17:25:09   投稿:hebedich  
c++中關鍵字有幾十個,其中類型修飾關鍵字有l(wèi)ong, short, singed, unsigned。今天我們就來談一下經常被大家忽視的signed關鍵字

我們都知道且經常用到 unsigned 關鍵字,但有沒有想過,與此對應的 signed 關鍵字有啥用?

復制代碼 代碼如下:

int i = 0;
signed int i = 0;

這倆有區(qū)別嗎?沒區(qū)別,看起來,signed 完全是個累贅。

真的是這樣嗎?

我查閱了 C++11 的標準文檔(草稿N3690),發(fā)現一些端倪:

3.9.1 Fundamental types

復制代碼 代碼如下:

Objects declared as characters(char) shall be large enough to store any member of the implementation's basic character set. If a character from this set is stored in a character object, the integral value of that character object is equal to the value of the single character literal form of that character. It is implementation-defined whether a char object can hold negative values. Characters can be explicitly declared unsigned or signed. Plain char, signed char, and unsigned char are three distinct types, collectively called narrow character types. A char,a signed char,and an unsigned char occupy the same amount of storage and have the same alignment requirements(3.11); that is,they have the same object representation. For narrow character types, all bits of the object representation participate in the value representation. For unsigned narrow character types, all possible bit patterns of the value representation represent numbers. These requirements do not hold for other types. In any particular implementation, a plain char object can take on either the same values as a signed char or an unsigned char; which one is implementation-defined.

標準規(guī)定的很清楚,char, signed char 和 unsigned char 是三種不同的類型。 char 會根據具體實現場景,而決定到底是 signed 還是 unsigned.

再看看 C11 的標準文檔(ISO/IEC 9899:201x)呢?

6.7.2 Type specifiers

復制代碼 代碼如下:

Each of the comma-separated multisets designates the same type, except that for bit-fields, it is implementation-defined whether the specifier int designates the same type as signed int or the same type as unsigned int.

看來,bit-fields (位域) 也存在同樣的問題。(位域的概念可能也有點偏,經常寫比較底層的接口或協(xié)議童鞋應該熟悉,可參考這里)

結論

在 C/C++ 中,signed 關鍵字絕大多數情況下都是累贅,但對于上述所言的兩種情況,即在 char 與 bit-fields 的使用過程中,還是有比較隱晦的作用的。

給自己提個醒,總是好的。

相關文章

  • C++ 中std::vector<T>的幾種清除方式

    C++ 中std::vector<T>的幾種清除方式

    std::vector<T>?可以通過多種方式清除(刪除所有元素),本文主要介紹了C++ 中std::vector<T>的幾種清除方式,具有一定的參考價值,感興趣的可以了解一下
    2025-04-04
  • C++實現百度坐標(BD09)及GCJ02與WGS84之間的轉換

    C++實現百度坐標(BD09)及GCJ02與WGS84之間的轉換

    這篇文章主要為大家詳細介紹了C++實現百度坐標(BD09)及GCJ02與WGS84之間的轉換的方法,文中的示例代碼講解詳細,希望對大家有所幫助
    2023-03-03
  • C語言編寫實現學生管理系統(tǒng)

    C語言編寫實現學生管理系統(tǒng)

    這篇文章主要為大家詳細介紹了C語言編寫實現學生管理系統(tǒng),文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2022-07-07
  • C++學習之命名空間詳解

    C++學習之命名空間詳解

    C++中,命名空間(namespace)是一個重要的概念。命名空間可以為函數、變量、類等定義作用域,避免與其他定義的名稱發(fā)生沖突。下面我們就來了解一下如何使用C++命名空間,以及一些常見的操作吧
    2023-04-04
  • C++中Operator類型強制轉換成員函數解析

    C++中Operator類型強制轉換成員函數解析

    轉換函數定義了由<類型說明符1>到<類型說明符2>之間的映射關系。可見,轉換函數是用來將一種類型的數據轉換成為另一種類型
    2013-09-09
  • C語言音樂播放器實例代碼

    C語言音樂播放器實例代碼

    文章給大家分享了用C語言音樂播放器的實例代碼,對此有需要的朋友參考學習下。
    2018-07-07
  • QT實現貪吃蛇游戲代碼詳解

    QT實現貪吃蛇游戲代碼詳解

    本文主要為大家詳細介紹了在QT中實現貪吃蛇游戲的詳細教程,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2021-11-11
  • C++ opencv ffmpeg圖片序列化實現代碼解析

    C++ opencv ffmpeg圖片序列化實現代碼解析

    這篇文章主要介紹了C++ opencv ffmpeg圖片序列化實現代碼解析,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友可以參考下
    2020-08-08
  • 基于Qt實現的自定義樹結構容器

    基于Qt實現的自定義樹結構容器

    在Qt框架中,盡管其提供了許多強大的容器類,但缺少一個通用的、靈活的樹結構容器,所以本文將設計并實現一個可復用的自定義樹結構容器,需要的可以參考下
    2024-12-12
  • 詳解C++ new-handler機制

    詳解C++ new-handler機制

    這篇文章主要介紹了C++ new-handler機制的相關資料,幫助大家更好的理解和使用c++,感興趣的朋友可以了解下
    2020-11-11

最新評論

蓬安县| 洛浦县| 理塘县| 三门峡市| 桃江县| 平凉市| 外汇| 抚松县| 明水县| 上虞市| 锦州市| 灵台县| 那曲县| 日照市| 交口县| 平安县| 临颍县| 昌乐县| 达孜县| 潜山县| 习水县| 石台县| 儋州市| 襄垣县| 滁州市| 遂溪县| 陇西县| 榆树市| 吉水县| 德令哈市| 科技| 奉贤区| 平南县| 宕昌县| 秦皇岛市| 勃利县| 赣州市| 汕头市| 清镇市| 小金县| 光山县|