How to fix C error 'unknown type name intptr_t'
Problem:
You have C code like
example.c
int v = 123;
intptr_t vptr = (intptr_t)&v;
but when you try to compile it you see an error message like
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
Solution
Add
fix.c
#include <stdint.h>
at the top of the source file where the error occured.
Check out similar posts by category:
C/C++, GCC Errors
If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow