f



"cannot convert parameter from 'short **' to 'void **'"

int func(void**);

{
    short* p = NULL;
    func(&p); //<<< here
}

Could somebody remind me why is this not allowed ?
error message: "cannot convert parameter from 'short **' to 'void **'"

Thanks,
Igor


0
igor3646 (3)
11/22/2005 6:14:23 PM
comp.lang.c++ 49423 articles. 7 followers. Post Follow

5 Replies
943 Views

Similar Articles

[PageSpeed] 0

On 2005-11-22, Igor Okulist <igor@remove_this_okulist.com> wrote:
> int func(void**);
>
> {
>     short* p = NULL;
>     func(&p); //<<< here
> }
>
> Could somebody remind me why is this not allowed ? error
> message: "cannot convert parameter from 'short **' to 'void
> **'"

You're attempting to automatically convert a pointer to pointer
to short to a pointer to pointer to void.

A pointer to pointer to void hasn't got the special semantics of
a void pointer.

-- 
Neil Cerutti
0
leadvoice (231)
11/22/2005 6:31:01 PM
Igor Okulist wrote:
> int func(void**);
> 
> {
>     short* p = NULL;
>     func(&p); //<<< here
> }
> 
> Could somebody remind me why is this not allowed ?
> error message: "cannot convert parameter from 'short **' to 'void **'"
> 
Because while a short* value can be converted to a void*, it's
not the case that they are the same format.  short** and void** are
therefore not convertible.

Imagine that you have an architecture where a char* (and hence
void*) are 32 bits byte addressed and a short pointer is word
addressed.

When you do
	short s;
	short* sp = &s;
	void* vp = sp;
the compiler needs to shift the short value to the left to store
it in the void pointer.

However, if you were allowed to do this:
	void** vpp = &sp;

How would the compiler know to convert the short* value?
0
ron131 (898)
11/22/2005 6:46:41 PM
> You're attempting to automatically convert a pointer to pointer
> to short to a pointer to pointer to void.
>
> A pointer to pointer to void hasn't got the special semantics of
> a void pointer.
>
> -- 
> Neil Cerutti

Neil,

Is there a reason why the semantics do not apply to void**? or just
no body bothered to specify it? The stride will always be the same (
lets disregard the near/far possibility).

Thanks,
Igor


0
igor3646 (3)
11/22/2005 6:51:29 PM
Igor Okulist wrote:
> int func(void**);
>
> {
>     short* p = NULL;
>     func(&p); //<<< here
> }
>
> Could somebody remind me why is this not allowed ?
>

http://www.parashift.com/c++-faq-lite/proper-inheritance.html#faq-21.2

ALthough it speaks to classes the same logic would apply.

0
roberts.noah (1664)
11/22/2005 8:08:19 PM
Igor Okulist wrote:
> int func(void**);
>
> {
>     short* p = NULL;
>     func(&p); //<<< here
> }
>
> Could somebody remind me why is this not allowed ?
>

http://www.parashift.com/c++-faq-lite/proper-inheritance.html#faq-21.2

ALthough it speaks to classes the same logic would apply.

0
roberts.noah (1664)
11/22/2005 8:10:46 PM
Reply: