Re: [PATCH] Trivial warning fix for imap-send.c
- From
- H. Peter Anvin <hpa@zytor.com>
- Date
- Mar 13, 2006, 02:59 UTC
- Message-ID
- <4414E000.9030902@zytor.com>
- In-Reply-To
- <4414747B.7040700@gmail.com>
A Large Angry SCM wrote:
Show 18 quoted lines
> Mark Wooding wrote: > >> Linus Torvalds <torvalds@osdl.org> wrote: >> >>> So in modern C, using NULL at the end of a varargs array as a pointer >>> is perfectly sane, and the extra cast is just ugly and bowing to bad >>> programming practices and makes no sense to anybody who never saw the >>> horror that is K&R. >> >> No! You can still get bitten. You're lucky that on common platforms >> all pointers look the same, but if you find one where `char *' (and >> hence `void *') isn't the same as `struct foo *' then, under appropriate >> circumstances you /will/ unless you put the casts in. > > Please explain how malloc() can work on such a platform. My reading of > the '89 ANSI C spec. finds that _ALL_ (non function) pointers _are_ > cast-able to/from a void * and that NULL should be #defined as (void *). > See 3.2.2.3 and 4.1.5 if interested.
Consider the non-hypothetical example of a word-addressed machine, which has to have extra bits in a subword pointer like char *. The C standard requires that void * has those bits as well, but it doesn't means that any void * can be cast to any arbitrary pointer -- the opposite, however, is required.
-hpa