$ 5.2.9 / 2 -
"The expression e can be explicitly converted to type T using static_cast of the form static_cast (e) if the declaration is" T t (e) "; well-formed, for some I came up with a temporary variable t (8.5). The effect of such an explicit conversion is the same that both executing the declaration and initializing 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 the value is rvalue otherwise.The expression e is used as an l value if and only if initialization uses it as an lvalue. "
Let's look at code snippet 1 below
float *f;
void *p = f;
Here the initialization "p" is well formed. This corresponds to $ 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 take the code in OP
In our case, "E" is 'float **' , and 'T' is 'void **'
So, will static_cast work for a conversion attempt if 'p' can be initialized as shown below.
float **f;
void **p = f;
The initialization of 'p' is poorly formed because it is not a valid condition specified in $4.10
Now, having come to why b = (void**)(&a); ?
In this case, an explicit cast is used ( $5.4 ). In this case, this explicit cast is equivalent to reinterpret_cast ( $5.4/5 ). In this particular case, this conversion is allowed ( $5.2.1/7 ).
Does it help?
source share