如何修复 C 错误 'unknown type name intptr_t'

问题:

你有类似这样的 C 代码

example.c
int v = 123;
intptr_t vptr = (intptr_t)&v;

但当你尝试编译它时,你看到类似这样的错误消息

compile_error.txt
main.c: In function ‘main’:
main.c:5:1: error: unknown type name ‘intptr_t’; did you mean ‘__int128_t’?
 intptr_t vptr = (intptr_t)&v;
 ^~~~~~~~
 __int128_t
main.c:5:18: error: ‘intptr_t’ undeclared (first use in this function)
 intptr_t vptr = (intptr_t)&v;
                  ^~~~~~~~
main.c:5:18: note: each undeclared identifier is reported only once for each function it appears in

解决方案

添加

fix.c
#include <stdint.h>

在错误发生的源文件顶部。


Check out similar posts by category: C/C++, GCC Errors