471,850 Members | 878 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

const void *

What purpose does qualifying
a pointer to void with const
really serve? Before you can use what
the pointer points to, you must cast
it to the appropriate pointer type.
Then, you may as well include the
const qualification in the case. Being that
the const qualification serves no point
upon casting the pointer to void to some
other pointer type.

For example, take a look at 'free'.
Why is the parameter type 'const void *'?
What purpose is it really serving?

--
conrad

Sep 20 '06 #1
2 9915
co****@lawyer.com wrote:
What purpose does qualifying
a pointer to void with const
really serve? Before you can use what
the pointer points to, you must cast
it to the appropriate pointer type.
No, void pointers will be implicitly converted to other pointer types
with the same or greater cv qualifications. This means that the
following implicit conversions are valid:

void* -const void*
void* -char*
void* -const char*
const void * -const char*

while the following are not:

const void* -void*
const void* -char*
Then, you may as well include the
const qualification in the case. Being that
the const qualification serves no point
upon casting the pointer to void to some
other pointer type.

For example, take a look at 'free'.
Why is the parameter type 'const void *'?
What purpose is it really serving?
So you can pass a const pointer without a cast.

--
Clark S. Cox III
cl*******@gmail.com
Sep 20 '06 #2
co****@lawyer.com wrote:
What purpose does qualifying
a pointer to void with const
really serve? Before you can use what
the pointer points to, you must cast
it to the appropriate pointer type.
Then, you may as well include the
const qualification in the case. Being that
the const qualification serves no point
upon casting the pointer to void to some
other pointer type.

For example, take a look at 'free'.
Why is the parameter type 'const void *'?
<snip>

But it isn't. Quoth ISO/IEC 9899:1999:

7.20.3.2 The free function

Synopsis

1 #include <stdlib.h>
void free(void *ptr);

What purpose is it really serving?
A const pointer as a function argument generally means something to the
extent of "This function promises not to modify what the pointer points
to."
Mark F. Haigh
mf*****@sbcglobal.net

Sep 20 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by Virendra Verma | last post: by
4 posts views Thread by Mahesh Tomar | last post: by
13 posts views Thread by herrcho | last post: by
7 posts views Thread by al | last post: by
14 posts views Thread by Enrico `Trippo' Porreca | last post: by
16 posts views Thread by hzmonte | last post: by
4 posts views Thread by grizggg | last post: by
reply views Thread by wellingj | last post: by
reply views Thread by YellowAndGreen | last post: by
aboka
reply views Thread by aboka | last post: by

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.