473,405 Members | 2,154 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

"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
Nov 23 '05 #1
9 3484
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
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
> 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
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

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

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
> 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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: mike | last post by:
regards: I use Jtidy (api) to translate a HTML file into a "XHTML file". But The "XHTML file" cannot be identified by nokia 6600. Do I miss something important? Or this is Jtidy's weakness or...
6
by: Otto Wyss | last post by:
I've the following function declaration: wxTree GetLastChild (const wxTree& item, long& cookie) const; I'd like to make the cookie parameter optional, i.e. "long& cookie = ....", without...
40
by: Dave Hansen | last post by:
Please note crosspost. Often when writing code requiring function pointers, it is necessary to write functions that ignore their formal parameters. For example, a state machine function might...
0
by: Chun | last post by:
Dear All I am now facing a problem when i try to pass a custom datatable datatype value to a remote server. In the remote server, a method with System.Data.DataTable as input parameter is...
4
by: Supra | last post by:
value of type "Integer" cannot be convert to system.color Public Sub APIHighlight2(ByVal BgColour As Integer, ByVal FgColour As Integer) SelectionHighlightBackColour(BgColour) Dim rtb As New...
15
by: Bjorn Jensen | last post by:
Hi! An beginner question: Pleas help me with this (-: Error (the arrow points on the s in sqrt) ===== tal.java:6: cannot find symbol symbol : method sqrt(int) location: class tal...
7
by: John Layton | last post by:
Hi there, Is it possible to pass null to a function taking an "out" (or "ref") parameter in C#. I'd like to do something like the following (which doesn't compile of course). Thanks in advance....
1
by: stillh2os | last post by:
Hello. I'm new to .NET, and I'm trying to implement a callback function. I want my managed C++ code to call an unmanaged function, passing in a callback function that the unmanaged C/C++ code...
2
by: qazmlp1209 | last post by:
class base { public: base() { } base(int number) { priNumber = number ;
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.