Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

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.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7602571
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T23:26:40+00:00 2026-05-30T23:26:40+00:00

Is it a good idea to use intptr_t as a general-purpose storage (to hold

  • 0

Is it a good idea to use intptr_t as a general-purpose storage (to hold pointers and integer values) instead of void*? (As seen here: http://www.crystalspace3d.org/docs/online/manual/Api1_005f0-64_002dBit-Portability-Changes.html)

For what I’ve already read:

  • int -> void* -> int roundtrip is not guaranteed to hold original value; I guess int -> intptr_t -> int will do
  • pointer arithmetics on both void* and intptr_t require casts, so none gets advantage here
  • void* means less explicit casts when storing pointers, intptr_t means less casts when storing integer values
  • intptr_t requires C99

What else should I take into consideration?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T23:26:42+00:00Added an answer on May 30, 2026 at 11:26 pm

    Is it a good idea to use intptr_t as a general-purpose storage (to hold pointers and integer values) instead of void*?

    No.

    intptr_t is not guaranteed to exist. First, as you note, it was introduced in C99. Second, implementations are not required to have an integer type big enough to hold converted pointer values without loss of information.

    Converting an int to intptr_t and back is unlikely to lose information but there’s no actual guarantee that intptr_t is wider than int.

    If you want to store pointer values, store them in pointer objects. That’s what pointer objects are for.

    Any pointer to an object or incomplete type can be converted to void* and back again without loss of information. There is no such guarantee for pointers to functions — but any pointer-to-function type can be converted to any other pointer-to-function-type and back without loss of information. (I’m referring to the C standard; I think POSIX provides some additional guarantees.)

    If you want to store either an integer or a pointer value in the same object, the first thing you should do is re-think your design. If you’ve already done so, and concluded that you really do want to do this, consider using a union (and keeping careful track of what kind of value you’ve stored most recently).

    There are APIs that use a void* argument to allow arbitrary data to be passed; see, for example, the POSIX pthread_create() function. This can be abused by casting an integer value to void* but it’s safer to pass the address of an integer object.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is it a good idea to use #include randombytes.cpp instead of randombytes.h in my
Is it a good idea to use IEEE754 floating point NaN (not-a-number) for values
Is it good idea to use Memcached for session storage with PHP? We will
This is a general software design question. Is it a good idea to use
Is it a good idea to use while loop instead of a cursor? What
Is it a good idea to use MongoDB in .NET desktop application?
Is it a good idea to use C99 VLA? When is it appropriate to
I understand from Papa Crockford that it's a good idea to use semicolons. And
Is it a good idea to use sockets to send data between two servers,
Is it a good idea to use experimental CSS-properties like border-radius , text-shadow ,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.