問題描述
我看到用這種類型定義的變量,但我不知道它來自哪里,也不知道它的目的是什么.為什么不使用 int 或 unsigned int?(其他類似"類型呢?Void_t 等).
I see variables defined with this type but I don't know where it comes from, nor what is its purpose. Why not use int or unsigned int? (What about other "similar" types? Void_t, etc).
推薦答案
來自 維基百科
stdlib.h
和 stddef.h
頭文件定義了一個名為 size_t
1 用于表示對象的大小.接受大小的庫函數期望它們是 size_t
類型,并且 sizeof 運算符的計算結果為 size_t
.
The
stdlib.h
andstddef.h
header files define a datatype calledsize_t
1 which is used to represent the size of an object. Library functions that take sizes expect them to be of typesize_t
, and the sizeof operator evaluates tosize_t
.
size_t
的實際類型是平臺相關的;一個常見的錯誤是假設 size_t
與 unsigned int 相同,這會導致編程錯誤,2 特別是隨著 64 位架構變得越來越流行.
The actual type of size_t
is platform-dependent; a common mistake is to assume size_t
is the same as unsigned int, which can lead to programming errors,2 particularly as 64-bit architectures become more prevalent.
來自 C99 7.17.1/2
以下類型和宏定義在標準頭文件stddef.h
The following types and macros are defined in the standard header
stddef.h
size_t
這是sizeof運算符結果的無符號整數類型
which is the unsigned integer type of the result of the sizeof operator
這篇關于我在哪里可以找到 size_t 的定義?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!