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

  • Home
  • SEARCH
  • 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 9117543
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T04:55:13+00:00 2026-06-17T04:55:13+00:00

void* is a useful feature of C and derivative languages. For example, it’s possible

  • 0

void* is a useful feature of C and derivative languages. For example, it’s possible to use void* to store objective-C object pointers in a C++ class.

I was working on a type conversion framework recently and due to time constraints was a little lazy – so I used void*… That’s how this question came up:

Why can I typecast int to void*, but not float to void* ?

  • 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-06-17T04:55:14+00:00Added an answer on June 17, 2026 at 4:55 am

    BOOL is not a C++ type. It’s probably typedef or defined somewhere, and in these cases, it would be the same as int. Windows, for example, has this in Windef.h:

        typedef int                 BOOL;
    

    so your question reduces to, why can you typecast int to void*, but not float to void*?

    int to void* is ok but generally not recommended (and some compilers will warn about it) because they are inherently the same in representation. A pointer is basically an integer that points to an address in memory.

    float to void* is not ok because the interpretation of the float value and the actual bits representing it are different. For example, if you do:

       float x = 1.0;
    

    what it does is it sets the 32 bit memory to 00 00 80 3f (the actual representation of the float value 1.0 in IEEE single precision). When you cast a float to a void*, the interpretation is ambiguous. Do you mean the pointer that points to location 1 in memory? or do you mean the pointer that points to location 3f800000 (assuming little endian) in memory?

    Of course, if you are sure which of the two cases you want, there is always a way to get around the problem. For example:

      void* u = (void*)((int)x);        // first case
      void* u = (void*)(((unsigned short*)(&x))[0] | (((unsigned int)((unsigned short*)(&x))[1]) << 16)); // second case
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: What is useful about a reference-to-array parameter? Are void myFunction( int (&arg)[4]
I am looking for a class that defines a holding structure for an object.
A useful feature in Java is the option to declare a member method as
I use a autocomplete feature for comboboxes from Glazed Lists. It's pretty usefull. I
Let's say I have a class A { int A1; void Af(); }; Then
I want to make a http request with android. is use this: void testHTTP()
class TestClass { private string _privateString = hello; void ChangeData() { TestClass otherTestClass =
I've found a useful article that explains how to make Jersey to use SLF4J
This would be useful for consistently naming methods, for example let's take a look
I was studying the visitor pattern and came across this useful example: https://stackoverflow.com/a/2604798/974594 .

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.