簡體   English   中英

ptrdiff_t在C中定義在哪里?

[英]Where is ptrdiff_t defined in C?

ptrdiff_t在C中定義在哪里?

它在stddef.h定義。


該頭文件定義了整數類型size_tptrdiff_twchar_t 、函數宏offsetof和常量宏NULL

如果您在 Visual Studio 2015 或更高版本中尋找ptrdiff_t ,請務必注意,微軟再次打破所有可能的約定,因為他們的stddef.h版本中沒有定義ptrdiff_t ,自 Visual Studio 2015 以來,該版本已成為 Unversal 的一部分CRT(它是 Windows SDK 的一部分)。

stddef.h中的所有類型定義現在都位於vcruntime.h中——只有offsetof()仍在stddef.h中。 而不是包括stddef.h你應該包括stdint.h其中包括vcruntime.h

如果你需要它跨平台工作或與舊版本的 Visual Studio 一起工作,你可以使用這樣的東西:

#if defined(_MSC_VER) && (_MSC_VER >= 1900) // UCRT was introduced in VS 2015
#include <stdint.h>
#else
#include <stddef.h>
#endif

由於@Good Person表示這不是特定於Linux,因此在Microsoft Visual Studio中, ptrdiff_t的定義如下:

C:\\ Program Files(x86)\\ Microsoft Visual Studio \\ 2017 \\ Enterprise \\ VC \\ Tools \\ MSVC \\ 14.15.26726 \\ include \\ vcruntime.h

它是由 POSIX 標准定義的: http : //pubs.opengroup.org/onlinepubs/9699919799/basedefs/stddef.h.html確切地說,類型可能是特定於實現的,但接口是 stddef.h

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM