Re: dereferencing void *
"maxw_cc" <email@example.com> wrote in message news:firstname.lastname@example.org om...
Please CROSS-POST if you think your article is subject to more than
one group; as I recall, this is not the first time you double-post to
comp.std.c and comp.lang.c.
> I've known and seen that dereferencing a void * is wrong.
It's not wrong, it's just useless.
> Looking at C90 or C99 I haven't
> found an explicit prohibition (violation of a constraint)
> for dereferencing a void *.
> So far the only justification generated from my interpretation
> of the standard is the following:
> C99 126.96.36.199 paragraph 4
> If the operand has type `pointer to type',
> the result has type `type'.
> Then dereferencing a void * will generate a
> a result that has `void' type.
> And then in 188.8.131.52
> 184.108.40.206 void
> 1 The (nonexistent) value of a void expression
> (an expression that has type void) shall not
> be used in any way, and implicit or explicit
> conversions (except to void) shall not be
> applied to such an expression...
> Then joining these two parts I make the following
> 'Even though it's not illegal to dereference a void *
> (it doesn't violate a constraint), dereferencing a void *
> will produce a result that has void type, and this result
> shall not be used in any way. So there's no practical or logical
> reason for dereferencing a void *.'
> Is my reasoning correct?
See this example:
void *pv = &i;
pv; /* okay */
*pv; /* okay */
&*pv; /* wrong */
pv = 0;
pv; /* okay */
*pv; /* wrong */
Someone can argue that dereferencing a pointer to void is disallowed
since the type "void" is not an lvalue (which designates an object),
but the committee has already formed the authoritative interpretation
in DR106 for C90, and I think it's not harmful than double-posting.
Jun, Woong (email@example.com)
Dept. of Physics, Univ. of Seoul
|All times are GMT. The time now is 03:26 AM.|
Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.