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 339439
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T10:31:23+00:00 2026-05-12T10:31:23+00:00

I want to reinterpret cast a function pointer into a void* variable. The type

  • 0

I want to reinterpret cast a function pointer into a void* variable. The type of the function pointer will be of type Class* (*)(void*).

Below is the sample code,

class Test
{
    int a;
};

int main()
{
    Test* *p(void **a);
    void *f=reinterpret_cast<void*>(p);     
}

The above code works well with Visual Studio/x86 compilers. But with ARM compiler, it gives compilation error. Don’t know why.

Error: #694: reinterpret_cast cannot
cast away const or other type
qualifiers

I read the explanation in Casting a function pointer to another type

I was concerned about the below explanation.

Casting between function pointers and
regular pointers (e.g. casting a void
(*)(void)
to a void*). Function
pointers aren’t necessarily the same
size as regular pointers, since on
some architectures they might contain
extra contextual information. This
will probably work ok on x86, but
remember that it’s undefined behavior.

How to do such conversions from void (*)(void*) -> void* effectively so that atleast it compiles almost the same in most of the compilers ?

  • 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-12T10:31:24+00:00Added an answer on May 12, 2026 at 10:31 am

    reinterpret_cast can’t be used to cast a pointer to function to a void*. While there are a few additional things that a C cast can do which aren’t allowed by combination of static, reinterpret and const casts, that conversion is not one of them.

    In C the cast is allowed, but it’s behavior isn’t defined (i.e. even round trip isn’t guaranteed to work).

    Some POSIX functions need the conversion to be well useful.

    I’ve played with several compilers I’ve here:

    • none prevent the C cast, even in the highest conformance mode. Some give a warning depending on the warning and conformance level, others gave no warning whatever I tried.
    • the reinterpret_cast was a error with some compilers even in the more relaxed level while other accepted it in all case without ever giving a warning.

    In the last available draft for C++0X, the reinterpret_cast between function pointers and objects pointers is conditionally supported.

    Note that if that make sense or not will depend on the target more than the compiler: a portable compiler like gcc will have a behavior imposed by the target architecture and possibly ABI.

    As other have make the remark,

    Test* *p(void **a);
    

    defines a function, not a pointer to function. But the function to pointer to function implicit conversion is made for the argument to reinterpret_cast, so what reinterpret_cast get is a Test** (*p)(void** a).

    Thanks to Richard which makes me revisit the issue more in depth (for the record, I was mistaken in thinking that the pointer to function to pointer to object was one case where the C cast allowed something not authorized by C++ casts combinations).

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

Sidebar

Ask A Question

Stats

  • Questions 194k
  • Answers 195k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer The SQL part of it might look like this: INSERT… May 12, 2026 at 6:52 pm
  • Editorial Team
    Editorial Team added an answer Your regular expression doesn't include a check for dashes -… May 12, 2026 at 6:52 pm
  • Editorial Team
    Editorial Team added an answer The first thing you need to know is are you… May 12, 2026 at 6:52 pm

Related Questions

I have a void pointer returned by dlsym(), I want to call the function
I have a file that I want to read and write to a binary
I want to create an allocator which provides memory with the following attributes: cannot
For a system I need to convert a pointer to a long then the

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.