473,503 Members | 3,247 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Trouble with variable types (void *)

Greetings!

Here's another problem that appeared recently:

I have the following function call:

l_test->Compress(&"filename.dat",l_buf);

l_test is a pointer-to-packer that I want to check here.
The file name thing should be plain enough, whereas l_buf is declared as a
char * and contains a pointer to a data buffer.
Compress() itself has the following declaration:

Compressor_Base : public Base
{
..
..
..
public:
void Compress(const char *p_name, void *p_buf);
}
p_name takes the name of a file that is to contain the (compressed) data, and
p_buf is a pointer-to-buffer, whose contents are to be compressed (the buffer
can contain any data type, and is of no relevance for the function).

l_test is declared as type Compressor_Base and should therefore correctly
reference the function Compress().

But when compiling the source I get the following error:
main.cpp:609: error: no matching function for call to `Compressor_Null::
Compress(const char (*)[31], char*&)'
compressor_base.h:88: error: candidates are: void
Compressor_Base::Compress(const char*, void*)

So, what's going on here?
I don't remember having included a *reference* to l_buf, and even prepending
(void *) to l_buf won't help.
Did I miss some peculiarities of void pointers, or is this some sort of bug?
Switching p_buf from void * to, for example, char * doesn't help, either - the
same type of error appears every time I attempt a compilation.

Any help would be appreciated.

--
Olaf Martens Linux User #246244 http://counter.li.org/
Hugo-Luther-Str. 8 E-Mail: ol*********@arcor.de
38118 Braunschweig Fon: +49-531-314834
"Who the heck is General Failure, and why is he reading my harddisk?"

Jul 22 '05 #1
8 1570
"Olaf Martens" <ol*********@arcor.de> wrote in message
news:40***********************@newsread4.arcor-online.net...
Here's another problem that appeared recently:

I have the following function call:

l_test->Compress(&"filename.dat",l_buf);
What's the "&" for?

l_test is a pointer-to-packer that I want to check here.
The file name thing should be plain enough, whereas l_buf is declared as a
char * and contains a pointer to a data buffer.
Compress() itself has the following declaration:

Compressor_Base : public Base
{
.
.
.
public:
void Compress(const char *p_name, void *p_buf);
}
p_name takes the name of a file that is to contain the (compressed) data, and p_buf is a pointer-to-buffer, whose contents are to be compressed (the buffer can contain any data type, and is of no relevance for the function).

l_test is declared as type Compressor_Base and should therefore correctly
reference the function Compress().

But when compiling the source I get the following error:
main.cpp:609: error: no matching function for call to `Compressor_Null::
Compress(const char (*)[31], char*&)'
compressor_base.h:88: error: candidates are: void
Compressor_Base::Compress(const char*, void*)

So, what's going on here?
Drop the ampersand.
I don't remember having included a *reference* to l_buf, and even prepending (void *) to l_buf won't help.
Did I miss some peculiarities of void pointers, or is this some sort of bug?

No, you missed the fact that you're not supposed to take addresses
of literals.
Switching p_buf from void * to, for example, char * doesn't help, either - the same type of error appears every time I attempt a compilation.


V
Jul 22 '05 #2
Olaf Martens wrote:
Greetings!

Here's another problem that appeared recently:

I have the following function call:

l_test->Compress(&"filename.dat",l_buf);
The first argument is of type const char (*)[13] (i.e. poiner to
constant array of 13 chars) here. I guess you actually meant:

l_test->Compress("filename.dat",l_buf);

where the argument is of type const char[13], which will be implicitly
converted to a pointer to its first element, i.e. a const char*.
l_test is a pointer-to-packer that I want to check here.
The file name thing should be plain enough, whereas l_buf is declared
as a char * and contains a pointer to a data buffer.
Compress() itself has the following declaration:

Compressor_Base : public Base
{
.
.
.
public:
void Compress(const char *p_name, void *p_buf);
}
p_name takes the name of a file that is to contain the (compressed)
data, and p_buf is a pointer-to-buffer, whose contents are to be
compressed (the buffer can contain any data type, and is of no
relevance for the function).

l_test is declared as type Compressor_Base and should therefore
correctly reference the function Compress().

But when compiling the source I get the following error:
main.cpp:609: error: no matching function for call to
`Compressor_Null:: Compress(const char (*)[31], char*&)'
compressor_base.h:88: error: candidates are: void
Compressor_Base::Compress(const char*, void*)

So, what's going on here?
I don't remember having included a *reference* to l_buf, and even
prepending (void *) to l_buf won't help.
The problem is not the second argument, but the first one. You are
providing a pointer to an array of char with 31 elements, while the
function wants a pointer to char.
Did I miss some peculiarities of void pointers, or is this some sort
of bug? Switching p_buf from void * to, for example, char * doesn't
help, either - the same type of error appears every time I attempt a
compilation.

Any help would be appreciated.


--
Tell a man that there are 400 billion stars and he'll believe you.
Tell him a bench has wet paint and he has to touch it.

Jul 22 '05 #3
Victor Bazarov schrieb:
"Olaf Martens" <ol*********@arcor.de> wrote in message
news:40***********************@newsread4.arcor-online.net...
Here's another problem that appeared recently:

I have the following function call:

l_test->Compress(&"filename.dat",l_buf);

What's the "&" for?

g++ would complain otherwise and issue a warning: Deprecated conversion of
string constants to char *...
[snip]

Drop the ampersand. It's the second parameter that bothers me, not the first!

[snip]

No, you missed the fact that you're not supposed to take addresses
of literals.

Oh, really? And why does g++ complain when omitting the &, then?
So, once more: The problem is *NOT* the string literal, but the second
parameter (l_buf)!!!

--
Olaf Martens Linux User #246244 http://counter.li.org/
Hugo-Luther-Str. 8 E-Mail: ol*********@arcor.de
38118 Braunschweig Fon: +49-531-314834
"Who the heck is General Failure, and why is he reading my harddisk?"

Jul 22 '05 #4
Olaf Martens wrote:
Victor Bazarov schrieb:
"Olaf Martens" <ol*********@arcor.de> wrote in message
news:40***********************@newsread4.arcor-online.net...
Here's another problem that appeared recently:

I have the following function call:

l_test->Compress(&"filename.dat",l_buf);

What's the "&" for?

g++ would complain otherwise and issue a warning: Deprecated
conversion of string constants to char *...


That doesn't make sense if your function really takes a const char* as
first parameter. That warning should only occur if the first parameter
is a pointer to non-const char.
[snip]

Drop the ampersand. It's the second parameter that bothers me, not the first!


Why?
[snip]

No, you missed the fact that you're not supposed to take addresses
of literals. Oh, really? And why does g++ complain when omitting the &, then?


That hasn't anything to do with it. It complains because a string
literal cannot be modified and therefore is of type array of const
char. And for that reason, you are not supposed to convert it to a
pointer to non-const char.
So, once more: The problem is *NOT* the string literal, but the second
parameter (l_buf)!!!


What makes you believe that?

Jul 22 '05 #5

"Olaf Martens" <ol*********@arcor.de> wrote in message
news:40***********************@newsread2.arcor-online.net...
Victor Bazarov schrieb:
"Olaf Martens" <ol*********@arcor.de> wrote in message
news:40***********************@newsread4.arcor-online.net...
Here's another problem that appeared recently:

I have the following function call:

l_test->Compress(&"filename.dat",l_buf);

What's the "&" for?

g++ would complain otherwise and issue a warning: Deprecated conversion of
string constants to char *...


[snip]

Drop the ampersand.

It's the second parameter that bothers me, not the first!


[snip]

No, you missed the fact that you're not supposed to take addresses
of literals.

Oh, really? And why does g++ complain when omitting the &, then?
So, once more: The problem is *NOT* the string literal, but the second
parameter (l_buf)!!!


Look at you error message, its the first parameter that is wrong.

See the bit that says const char (*)[31], that's what &"filename.dat" is
(apart from the length which is wrong). It does not match const char*.

Remove the &, and ignore the spurious and erroneous warning.

And try to believe knowledgeable people when they give you advice. If you
don't believe this, try removing the second parameter ENTIRELY (both from
the call and the function), and you will still get the same error message.

John
Jul 22 '05 #6
On Sun, 1 Feb 2004 20:14:24 -0000 in comp.lang.c++, "John Harrison"
<jo*************@hotmail.com> was alleged to have written:
Remove the &, and ignore the spurious and erroneous warning.


No, fix the cause of the perfectly legitimate warning.

If the function is going to modify the argument, it is a mistake to pass
it a quoted literal.

If it is not going to modify the argument, the argument should be const
which will get rid of the warning.

Jul 22 '05 #7

"David Harmon" <so****@netcom.com> wrote in message
news:40***************@news.west.earthlink.net...
On Sun, 1 Feb 2004 20:14:24 -0000 in comp.lang.c++, "John Harrison"
<jo*************@hotmail.com> was alleged to have written:
Remove the &, and ignore the spurious and erroneous warning.


No, fix the cause of the perfectly legitimate warning.

If the function is going to modify the argument, it is a mistake to pass
it a quoted literal.

If it is not going to modify the argument, the argument should be const
which will get rid of the warning.


In his quoted code the argument is const char*, therefore either he's
wrongly quoting his code or the compiler is wrong.

I do seem to recall one particular version of gcc getting this wrong, but I
might be imagining that.

John
Jul 22 '05 #8
On Sun, 1 Feb 2004 22:25:49 -0000 in comp.lang.c++, "John Harrison"
<jo*************@hotmail.com> was alleged to have written:
"David Harmon" <so****@netcom.com> wrote in message
news:40***************@news.west.earthlink.net. ..
On Sun, 1 Feb 2004 20:14:24 -0000 in comp.lang.c++, "John Harrison"
<jo*************@hotmail.com> was alleged to have written:
>Remove the &, and ignore the spurious and erroneous warning.


No, fix the cause of the perfectly legitimate warning.


In his quoted code the argument is const char*,


Oh well then, the warning is bogus.

Jul 22 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
5760
by: Jeff | last post by:
/* -------------------------------------------------------------------------- Hello, I was experimenting with class templates and specializing member functions and came across a simple problem...
4
3168
by: troloo | last post by:
Hello, I hope you can help me :)) The story goes as follows: I have a class with different methods and member variables. I store pointers to objects of this class inside a vector. Now, I would like...
14
2518
by: sathya_me | last post by:
Dear clc, I have a variable void *a; Since variable "a" can be assigned (point to) any type and also any type can be assigned to "a" (i.e means "a" = any typed variable; any typed variable =...
1
3257
by: Shawn | last post by:
As if it won't be clear enough from my code, I'm pretty new to C programming. This code is being compiled with an ANSI-C compatible compiler for a microcontroller. That part, I believe, will be...
11
3040
by: thierrydollar | last post by:
Hi, I have written a very simple program using variable arguments calls and I get strange things that I cannot explain. I have one function (add) that displays two parameters. It works well...
8
3147
sonic
by: sonic | last post by:
I am having trouble passing two variable types into my printPattern function. I need to pass rows and characterSelect from my getInput function into my printPattern function. I keep getting a...
12
1885
by: Santosh Krisnan | last post by:
hello all, I fiddled with BASIC in the early 90s but left it at that. Now I am trying to learn C. I tried to solve an exercise in my book, but it failes to compile. Can anyone tell me what the...
6
3196
by: CptDondo | last post by:
How do you declare a function with 0 or mroe arguments? I have a bunch of functions like this: void tc_cm(int row, int col); void tc_do(void); void tc_DO(int ln); and I am trying to ...
1
2765
by: ares.lagae | last post by:
- I have a typelist and I want to declare a member variable for each of the types. How can I do that? E.g. I have the typelist "typedef boost::mpl::vector<int, float> types;" and I want to declare...
0
7194
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
7070
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7267
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
5566
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,...
1
4993
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...
0
3160
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3148
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1495
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
729
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.