Mac OSX 应该有一个 "malloc.h" 文件吗?
Should Mac OSX have a "malloc.h" file?
客户的代码希望在 "usual suspect" 位置之一找到包含文件 malloc.h
。在我的 Mac、AFAICT 上,没有 malloc.h
,至少在任何你期望找到它的地方都没有,例如 /usr/include
、/usr/local/include
或 [=17] =].由于 malloc()
通常在 stdlib.h
中定义,并且由于代码无论如何都包含 stdlib.h,所以我能够通过注释掉 [=13= 的少数包含来构建代码].我正在使用 gcc
.
构建
但有两个问题:我的 gcc 是否有问题?那个文件应该在那里吗?此外,代码几乎立即因段错误而爆炸,我还没有能够追踪到。这可能是使用错误 malloc()
的结果吗?
malloc.h
已弃用,不应使用。它也包含一些 non-standard 功能。如果要使用 malloc
,则包括 stdlib.h
。甚至 C89 标准都没有提到 malloc.h
如果这是您问题的原因,我不知道,但很有可能。
下面的清单可以提供关于在哪里可以找到文件 should/could 的想法。不过,如果没有更多细节,我无法解释段错误。我看不出它与 malloc() 有任何关系。
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/sys/malloc.h
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/malloc/malloc.h
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/Kernel.framework/Versions/A/Headers/sys/malloc.h
/Applications/Xcode.app/Contents/Developer/Platforms/AppleTVOS.platform/Developer/SDKs/AppleTVOS.sdk/usr/include/malloc/malloc.h
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/usr/include/malloc/malloc.h
/Applications/Xcode.app/Contents/Developer/Platforms/WatchOS.platform/Developer/SDKs/WatchOS.sdk/usr/include/malloc/malloc.h
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/sys/malloc.h
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/malloc/malloc.h
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/Kernel.framework/Versions/A/Headers/sys/malloc.h
/Applications/Xcode.app/Contents/Developer/Platforms/WatchSimulator.platform/Developer/SDKs/WatchSimulator.sdk/usr/include/malloc/malloc.h
/Applications/Xcode.app/Contents/Developer/Platforms/AppleTVSimulator.platform/Developer/SDKs/AppleTVSimulator.sdk/usr/include/malloc/malloc.h
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/usr/include/malloc/malloc.h
$
客户的代码希望在 "usual suspect" 位置之一找到包含文件 malloc.h
。在我的 Mac、AFAICT 上,没有 malloc.h
,至少在任何你期望找到它的地方都没有,例如 /usr/include
、/usr/local/include
或 [=17] =].由于 malloc()
通常在 stdlib.h
中定义,并且由于代码无论如何都包含 stdlib.h,所以我能够通过注释掉 [=13= 的少数包含来构建代码].我正在使用 gcc
.
但有两个问题:我的 gcc 是否有问题?那个文件应该在那里吗?此外,代码几乎立即因段错误而爆炸,我还没有能够追踪到。这可能是使用错误 malloc()
的结果吗?
malloc.h
已弃用,不应使用。它也包含一些 non-standard 功能。如果要使用 malloc
,则包括 stdlib.h
。甚至 C89 标准都没有提到 malloc.h
如果这是您问题的原因,我不知道,但很有可能。
下面的清单可以提供关于在哪里可以找到文件 should/could 的想法。不过,如果没有更多细节,我无法解释段错误。我看不出它与 malloc() 有任何关系。
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/sys/malloc.h
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/malloc/malloc.h
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/Kernel.framework/Versions/A/Headers/sys/malloc.h
/Applications/Xcode.app/Contents/Developer/Platforms/AppleTVOS.platform/Developer/SDKs/AppleTVOS.sdk/usr/include/malloc/malloc.h
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/usr/include/malloc/malloc.h
/Applications/Xcode.app/Contents/Developer/Platforms/WatchOS.platform/Developer/SDKs/WatchOS.sdk/usr/include/malloc/malloc.h
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/sys/malloc.h
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/malloc/malloc.h
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/Kernel.framework/Versions/A/Headers/sys/malloc.h
/Applications/Xcode.app/Contents/Developer/Platforms/WatchSimulator.platform/Developer/SDKs/WatchSimulator.sdk/usr/include/malloc/malloc.h
/Applications/Xcode.app/Contents/Developer/Platforms/AppleTVSimulator.platform/Developer/SDKs/AppleTVSimulator.sdk/usr/include/malloc/malloc.h
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/usr/include/malloc/malloc.h
$