472,784 Members | 1,002 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,784 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 3438
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
by: Rina0 | last post by:
Cybersecurity engineering is a specialized field that focuses on the design, development, and implementation of systems, processes, and technologies that protect against cyber threats and...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

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.