Re: cast to 'void *'
- From: nicolas.sitbon@xxxxxxxxx
- Date: Sat, 6 Dec 2008 01:37:43 -0800 (PST)
On 5 déc, 23:06, Keith Thompson <ks...@xxxxxxx> wrote:
blargg....@xxxxxxxxxxxxx (blargg) writes:
Harald van =?UTF-8?b?RMSzaw==?= wrote:
On Fri, 05 Dec 2008 14:02:57 -0600, blargg wrote:
Rolf Magnus wrote:
Mark wrote:[...]
void *p;
int *x;
p = x;
x = p;
printf("p=%p, x=%p\n", p, (void *)x);
return 0;
}
When else is implicit conversion to 'void *' done, except assignment
like above written?
Basically everywhere except variable argument lists.
void* to/from function pointer is also not implicit.
Implementations commonly provide both implicit and explicit conversions
between void * and function pointers as extensions, and neither is
available in standard C.
Argh! My statement above was about as relevant as
void* to/from struct tm is also not implicit.
Apologies.
Except that conversion between void* and struct tm is a constraint
violation. There is no implicit conversion, so such a conversion
would have to done via a cast operator. C99 6.5.4p2-3 says:
Constraints
2 Unless the type name specifies a void type, the type name shall
specify qualified or unqualified scalar type and the operand shall
have scalar type.
3 Conversions that involve pointers, other than where permitted by
the constraints of 6.5.16.1, shall be specified by means of an
explicit cast.
Conversion between void* and a function pointer, as I just wrote
elsethread, violates no constraint, but its behavior is undefined (but
of course an implementation is free to define it).
Incidentally, it seems to me that paragraph 3 is superfluous; any case
where it would apply is already covered by other constraints.
--
Keith Thompson (The_Other_Keith) ks...@xxxxxxx <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
I agree with you, nevertheless, new POSIX standard (issue 7) says:
" 2.12.3 Pointer Types
18881
All function pointer types shall have the same
representation as the type pointer to void.
18882
Conversion of a function pointer to void * shall not
alter the representation. A void * value
18883
resulting from such a conversion can be converted back to
the original function pointer type,
18884
using an explicit cast, without loss of information.
18885
The ISO C standard does not require this, but
it is required for POSIX conformance.
Note:
18886
"
Therefore, if you program a POSIX compliant application, the
conversion with an explicit cast is permitted.
.
- References:
- cast to 'void *'
- From: Mark
- Re: cast to 'void *'
- From: Rolf Magnus
- Re: cast to 'void *'
- From: blargg
- Re: cast to 'void *'
- From: Harald van Dijk
- Re: cast to 'void *'
- From: blargg
- Re: cast to 'void *'
- From: Keith Thompson
- cast to 'void *'
- Prev by Date: Re: fgetc - end of line - where is 0xD?
- Next by Date: Re: strtok problem
- Previous by thread: Re: cast to 'void *'
- Next by thread: Re: cast to 'void *'
- Index(es):
Relevant Pages
|