git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] Trivial warning fix for imap-send.c

From
A Large Angry SCM <gitzilla@gmail.com>
Date
Mar 13, 2006, 04:36 UTC
Message-ID
<4414F6B1.9080107@gmail.com>
In-Reply-To
<4414E000.9030902@zytor.com>
H. Peter Anvin wrote:
Show 25 quoted lines
> A Large Angry SCM wrote:
>> 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.
ANSI X3.159-1989
3.2.2.3 Pointers
	A pointer to *void* may be converted to or from a pointer to any 
incomplete or object type. A pointer to any incomplete or object type 
may be converted to a pointer to *void* and back again; the result shall 
compare equal to the original pointer.

For any qualifier /q/, a pointer to a non-/q/-qualified type may be converted to a pointer to the /q/-qualified version of the type; the values stored in the original and converted pointers shall compare equal.

In integral constant expression with value 0, or such an expression cast to type <bold>void *</bold>, is called a /null pointer constant.[*33*] If a null pointer constant is assigned to or compared for equality to a pointer, the constant is converted to a pointer of that type. Such a pointer, called a /null pointer/, is guaranteed to compare unequal to a pointer to any object or function.

Two null pointers, converted through possibly different sequences of casts to pointer types, shall compare equal.

[*33*] the macro *NULL* is defined in <stddef.h> as a null pointer constant; see 4.1.5.

Previous: H. Peter AnvinNext: Linus Torvalds
Message 13 of 20 in “Trivial warning fix for imap-send.c”
  1. Trivial warning fix for imap-send.cArt Haas, Mar 11, 2006
  2. Mark WoodingMar 12, 2006
  3. Junio C HamanoMar 12, 2006
  4. Use explicit pointers for execl...() sentinels.Mark Wooding, Mar 12, 2006
  5. Timo HirvonenMar 12, 2006
  6. Mark WoodingMar 12, 2006
  7. Timo HirvonenMar 12, 2006
  8. Jeff KingMar 13, 2006
  9. Linus TorvaldsMar 12, 2006
  10. Mark WoodingMar 12, 2006
  11. A Large Angry SCMMar 12, 2006
  12. H. Peter AnvinMar 13, 2006
  13. A Large Angry SCMMar 13, 2006
  14. Linus TorvaldsMar 13, 2006
  15. H. Peter AnvinMar 13, 2006
  16. Linus TorvaldsMar 13, 2006
  17. Olivier GalibertMar 13, 2006
  18. Jeff KingMar 13, 2006
  19. H. Peter AnvinMar 13, 2006
  20. Linus TorvaldsMar 12, 2006

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.