欧美大屁股bbbbxxxx,狼人大香伊蕉国产www亚洲,男ji大巴进入女人的视频小说,男人把ji大巴放进女人免费视频,免费情侣作爱视频

歡迎來到入門教程網(wǎng)!

C語言

當(dāng)前位置:主頁 > 軟件編程 > C語言 >

詳談signed 關(guān)鍵字

來源:本站原創(chuàng)|時(shí)間:2020-01-10|欄目:C語言|點(diǎn)擊: 次

我們都知道且經(jīng)常用到 unsigned 關(guān)鍵字,但有沒有想過,與此對應(yīng)的 signed 關(guān)鍵字有啥用?

復(fù)制代碼 代碼如下:

int i = 0;
signed int i = 0;

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

真的是這樣嗎?

我查閱了 C++11 的標(biāo)準(zhǔn)文檔(草稿N3690),發(fā)現(xiàn)一些端倪:

3.9.1 Fundamental types

復(fù)制代碼 代碼如下:

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.

標(biāo)準(zhǔn)規(guī)定的很清楚,char, signed char 和 unsigned char 是三種不同的類型。 char 會(huì)根據(jù)具體實(shí)現(xiàn)場景,而決定到底是 signed 還是 unsigned.

再看看 C11 的標(biāo)準(zhǔn)文檔(ISO/IEC 9899:201x)呢?

6.7.2 Type specifiers

復(fù)制代碼 代碼如下:

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 (位域) 也存在同樣的問題。(位域的概念可能也有點(diǎn)偏,經(jīng)常寫比較底層的接口或協(xié)議童鞋應(yīng)該熟悉,可參考這里)

結(jié)論

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

給自己提個(gè)醒,總是好的。

上一篇:C語言函數(shù)語法詳解

欄    目:C語言

下一篇:C語言實(shí)現(xiàn)求定積分的方法

本文標(biāo)題:詳談signed 關(guān)鍵字

本文地址:http://mengdiqiu.com.cn/a1/Cyuyan/3161.html

網(wǎng)頁制作CMS教程網(wǎng)絡(luò)編程軟件編程腳本語言數(shù)據(jù)庫服務(wù)器

如果侵犯了您的權(quán)利,請與我們聯(lián)系,我們將在24小時(shí)內(nèi)進(jìn)行處理、任何非本站因素導(dǎo)致的法律后果,本站均不負(fù)任何責(zé)任。

聯(lián)系QQ:835971066 | 郵箱:835971066#qq.com(#換成@)

Copyright © 2002-2020 腳本教程網(wǎng) 版權(quán)所有