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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T15:13:55+00:00 2026-05-16T15:13:55+00:00

Just ran into this: #include <iostream> using namespace std; int main(int argc, char** argv)

  • 0

Just ran into this:

#include <iostream>

using namespace std;

int main(int argc, char** argv)
{
    float *a = new float[10];
    void **b;
    b = static_cast<void**>(&a);
    delete(a); 
    return 0;
}

macbook:C nils$ g++ -Wall -g -o static_cast static_cast.cpp 
static_cast.cpp: In function ‘int main(int, char**)’:
static_cast.cpp:9: error: invalid static_cast from type ‘float**’ to type ‘void**’
macbook:C nils$ clang++ -Wall -g -o static_cast static_cast.cpp 
static_cast.cpp:9:9: error: static_cast from 'float **' to 'void **' is not
      allowed
    b = static_cast<void**>(&a);
        ^~~~~~~~~~~~~~~~~~~~~~~
1 error generated.
macbook:C nils$ 

Why is it not allowed? While b = (void**)(&a); works.

  • 1 1 Answer
  • 1 View
  • 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-16T15:13:56+00:00Added an answer on May 16, 2026 at 3:13 pm

    $5.2.9/2 –

    “An expression e can be explicitly
    converted to a type T using a
    static_cast of the form
    static_cast(e) if the declaration
    “T t(e);” is well-formed, for some
    invented temporary variable t (8.5).
    The effect of such an explicit
    conversion is the same as performing
    the declaration and initialization and
    then using the temporary variable as
    the result of the conversion. The
    result is an lvalue if T is a
    reference type (8.3.2), and an rvalue
    otherwise. The expression e is used as
    an lvalue if and only if the
    initialization uses it as an lvalue.”

    Let us take the case of Code snippet 1 as below

    float *f;

    void *p = f;

    Here initialization of ‘p’ is well-formed. This is in accordance with $4.2

    An rvalue of type “pointer to cv T,” where T is an object type, can be converted to an rvalue of type “pointer to cv void.”

    Now let us take the code in OP

    In our case, ‘E’ is 'float **' and ‘T’ is 'void **'

    So, whether static_cast will work for the attempted conversion if ‘p’ can be initialized as shown below

    float **f;

    void **p = f;

    The initialization of ‘p’ is ill-formed as it is not a valid condition listed under $4.10

    Now, coming to why b = (void**)(&a); works?

    This is the case where an explicit cast is used ($5.4). In this case, this explicit cast is equivalent of reinterpret_cast ($5.4/5). In this particular case, this conversion is allowed ($5.2.1/7).

    Does this help?

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

Sidebar

Related Questions

I've just typed in an example from K&R... #include <stdio.h> int main (int argc,
I just ran into this issue while making a GET request to a node.js
I'm new in python, and just ran into this statement data = dict( (k,
I am just getting started with NHaml and ran into a snag. This is
I'm using ASP.NET MVC 3, and just ran into a 'gotcha' using the DropDownListFor
This is a very simplified version of some code I just ran into at
Hey guys, just learning about composition of classes and ran into this error. Gradebook.h
Just ran into this recently and I thought it'd be helpful to share. The
I just ran into this piece of code that does this : delete a,
I've just started playing around with Android Licensing and I ran into this problem.

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.