Re: Question about void pointers
- From: Tim Rentsch <txr@xxxxxxxxxxxxxxxxxxx>
- Date: 08 Oct 2008 23:22:41 -0700
Keith Thompson <kst-u@xxxxxxx> writes:
CBFalconer <cbfalconer@xxxxxxxxx> writes:
[...]
In addition, as far as I can tell, there is no prohibition against
returning void* and char* pointers in different registers (or other
entities). If this is correct, using the interchangeably can
create an ugly code block.
There is no such prohibition in the normative text of the standard,
but it's suggested in a footnote.
C99 6.2.5p27:
A pointer to void shall have the same representation and alignment
requirements as a pointer to a character type.
And a footnote:
The same representation and alignment requirements are meant to
imply interchangeability as arguments to functions, return values
from functions, and members of unions.
This is an unfortunate flaw in the standard.
I think you're misunderstanding the idea behind the footnote.
The "interchangeability" of char*/void* is meant to talk about
values of those types used in particular contexts, not about
derived types with those types in them. For example,
char *
xyzzy(){
void *r = "answer";
return * (char**) &r;
}
is the sort of case the footnote means to address. This
interchangeability does not extend to derived types, such as
trying to convert &xyzzy to (void *(*)()). There's a similar
relationship between int and unsigned int; as values, int and
unsigned int are (often) interchangeable, but pointers to int and
pointers to unsigned int don't bear any special relationship to
each other -- they don't even have to be the same size, for
example. The analogy with function types that have int or
unsigned int in them should be clear.
.
- Follow-Ups:
- Re: Question about void pointers
- From: Keith Thompson
- Re: Question about void pointers
- Prev by Date: Re: multi dimensional arrays as one dimension array
- Next by Date: Re: question realted to void *
- Previous by thread: Re: multi dimensional arrays as one dimension array
- Next by thread: Re: Question about void pointers
- Index(es):
Relevant Pages
|