Re: cast in memcpy()

From: Martin Dickopp (expires-2004-04-30_at_zero-based.org)
Date: 03/01/04


Date: Mon, 01 Mar 2004 11:41:27 +0100

Greg Barron <greg.barron@bigfoot.NOGARBAGE.com> writes:

> On Sun, 29 Feb 2004 20:14:52 -0800, Ben Pfaff <blp@cs.stanford.edu> wrote:
>
>> root@zworg.com (Amarendra GODBOLE) writes:
>>
>>> memcpy(arr, p, sizeof *p);
>>>
>>> Someone tells me -- this is an incorrect usage, you either need to do
>>> memcpy(arr, (char *)p, sizeof *p);
>>> or
>>> memcpy((void *)arr, (void *)p, sizeof *p);
>>
>> Your informant is wrong. No such casts are necessary in C.
>
> To be more specific, no casts are required to convert any pointer type
> to or from void *.

That only applies to pointers to objects, but not to function pointers.
The latter cannot be converted to `void *' (or vice versa) at all.

Martin

-- 
   ,--.    Martin Dickopp, Dresden, Germany                 ,= ,-_-. =.
  / ,- )   http://www.zero-based.org/                      ((_/)o o(\_))
  \ `-'                                                     `-'(. .)`-'
   `-.     Debian, a variant of the GNU operating system.       \_/