日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

C语言uint8_t和char的区别,c – int8_t和uint8_t是char类型吗?

發(fā)布時(shí)間:2024/3/13 编程问答 40 豆豆
生活随笔 收集整理的這篇文章主要介紹了 C语言uint8_t和char的区别,c – int8_t和uint8_t是char类型吗? 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

鑒于這個(gè)C 11計(jì)劃,我應(yīng)該期待看到一個(gè)數(shù)字還是一個(gè)字母?還是沒有期望?

#include

#include

int main()

{

int8_t i = 65;

std::cout << i;

}

標(biāo)準(zhǔn)是否指定此類型是否可以是字符類型?

解決方法:

根據(jù)C 0x FDIS(N3290)的§18.4.1[cstdint.syn],int8_t是一個(gè)可選的typedef,其指定如下:

namespace std {

typedef signed integer type int8_t; // optional

//...

} // namespace std

§3.9.1[basic.fundamental]陳述:

There are five standard signed integer types: “signed char”, “short int”, “int”, “l(fā)ong int”, and “l(fā)ong long int”. In this list, each type provides at least as much storage as those preceding it in the list. There may also be implementation-defined extended signed integer types. The standard and extended signed integer types are collectively called signed integer types.

Types bool, char, char16_t, char32_t, wchar_t, and the signed and unsigned integer types are collectively called integral types. A synonym for integral type is integer type.

§3.9.1還規(guī)定:

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.

很有可能得出結(jié)論,int8_t可能是char的typedef,前提是char對象采用有符號(hào)值;但是,情況并非如此,因?yàn)閏har不在有符號(hào)整數(shù)類型列表中(標(biāo)準(zhǔn)和可能擴(kuò)展的有符號(hào)整數(shù)類型).另請參見std :: make_unsigned和std :: make_signed上的Stephan T. Lavavej’s comments.

因此,int8_t是signed char的typedef,或者是擴(kuò)展的有符號(hào)整數(shù)類型,其對象恰好占用8位存儲(chǔ).

但是,要回答你的問題,你不應(yīng)該做出假設(shè).因?yàn)橐呀?jīng)定義了x.operator<

>模板< class traits> basic_ostream&LT炭,性狀&GT&安培;如果int8_t是簽名字符的完全匹配(即signed char的typedef),則將調(diào)用operator&,signed char)模板.

>否則,int8_t將被提升為int和basic_ostream< charT,traits>&將調(diào)用operator

在std :: cout<

>模板< class traits> basic_ostream&LT炭,性狀&GT&安培;如果uint8_t是unsigned char的完全匹配,則將調(diào)用operator&,unsigned char)模板.

>否則,因?yàn)閕nt可以表示所有uint8_t值,uint8_t將被提升為int和basic_ostream< charT,traits>&將調(diào)用operator

如果您總是想要打印一個(gè)角色,最安全,最明確的選擇是:

std::cout << static_cast(i);

如果你總想打印一個(gè)數(shù)字:

std::cout << static_cast(i);

標(biāo)簽:c,c11,language-lawyer,iostream,standard-library

來源: https://codeday.me/bug/20190923/1813451.html

總結(jié)

以上是生活随笔為你收集整理的C语言uint8_t和char的区别,c – int8_t和uint8_t是char类型吗?的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。