Which line is the correct (best) way for defining a pointer?
typedef ptrdiff_t pointer; // pointers are ptrdiff_t.
-- or --
typedef void* pointer; // pointers are void*.
pointer ptr = malloc(1024);
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Pointers in C are of type
T*whereTis the type pointed to;void*is the generic pointer type. Usually, you let C implicitly convertvoid*to something useful, e.g.ptrdiff_tis the type returned by the subtraction of two pointers, e.g.ptrdiff_tis an integral type, not a pointer type; you cannot use the indirection operator*on it. (Nor can you meaningfully use it on avoid*, by the way.)Had you wanted to store a pointer in an integer type,
uintptr_twould have been appropriate.