By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,497 Members | 2,010 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,497 IT Pros & Developers. It's quick & easy.

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

P: n/a
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
Nov 23 '05 #1
Share this Question
Share on Google+
9 Replies


P: n/a
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
Nov 23 '05 #2

P: n/a
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?
Nov 23 '05 #3

P: n/a
> 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
Nov 23 '05 #4

P: n/a
On 2005-11-22 13:51:29 -0500, "Igor Okulist"
<igor@remove_this_okulist.com> said:
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


Not always. Consider what would happen if sizeof(short*) !=
sizeof(void*), or if the two don't share the same internal
representation (both are possible).

--
Clark S. Cox, III
cl*******@gmail.com

Nov 23 '05 #5

P: n/a

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-lit....html#faq-21.2

ALthough it speaks to classes the same logic would apply.

Nov 23 '05 #6

P: n/a

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-lit....html#faq-21.2

ALthough it speaks to classes the same logic would apply.

Nov 23 '05 #7

P: n/a
> Not always. Consider what would happen if sizeof(short*) != sizeof(void*),
or if the two don't share the same internal representation (both are
possible).

--
Clark S. Cox, III
cl*******@gmail.com


I'll try to collect all responses here:
Consider what would happen if sizeof(short*) != sizeof(void*)

Well that would make life very complicated. Does that actually happen
(except the near/far pointers)? (this also address Ron's response)

Robert pointed to this faq:
http://www.parashift.com/c++-faq-lit....html#faq-21.2

I disagree (not with the FAQ), but the analogy does not apply here. When
converting
to void* pointer one explicitly casts it to (for lack of better word)
"void". Meaning
that if one is going to dereference it he/she will have to infer the type by
some
other means.

So, yes "Derived** ? Base** " is an error, but "something** -> void**"
still seems to make sense, since void** is not "is-a" relationship but just
a pointer
to a pointer to a memory location... or am I missing some improant step?

Thanks,
Igor


Nov 23 '05 #8

P: n/a
On 2005-11-22 19:16:07 -0500, "Igor Okulist"
<igor@remove_this_okulist.com> said:
Not always. Consider what would happen if sizeof(short*) !=
sizeof(void*), or if the two don't share the same internal
representation (both are possible).


Well that would make life very complicated. Does that actually happen
(except the near/far pointers)?


Yes. There is no requirement that all pointer types have the same size
and representation, and there are many platforms where this happens.

--
Clark S. Cox, III
cl*******@gmail.com

Nov 23 '05 #9

P: n/a
On 2005-11-23, Clark S Cox III <cl*******@gmail.com> wrote:
On 2005-11-22 19:16:07 -0500, "Igor Okulist"
<igor@remove_this_okulist.com> said:
Not always. Consider what would happen if sizeof(short*) !=
sizeof(void*), or if the two don't share the same internal
representation (both are possible).


Well that would make life very complicated. Does that actually
happen (except the near/far pointers)?


Yes. There is no requirement that all pointer types have the
same size and representation, and there are many platforms
where this happens.


Moreover, C++ doesn't need more than one kind of generic pointer.

void func(void*)
{
short *s;
func(&s);
}

What would the concept, "generic pointer to generic pointer"
mean, and how would it be used? What would it offer that a void*
doesn't?

--
Neil Cerutti
Nov 23 '05 #10

This discussion thread is closed

Replies have been disabled for this discussion.