Paul A.
Paul A.

Reputation: 449

memcpy doubts. Needs clarifications

I got a memcpy function that look strange on how it was used. I pasted it below. Can someone please help explain it. I do not know why the (void *). buffer is buffer in struct BLK. Thanks.

    memcpy(     
                (void *) (BLK->buffer + left),
                (void *) input,
                fill            
          );

Upvotes: 0

Views: 121

Answers (2)

dAm2K
dAm2K

Reputation: 10329

void *memcpy(void *dest, const void *src, size_t n);

may be the author wanted to be very sure that the compiler will not make errors doing its job :-)

In C, casting a object pointer from and to a void * is not needed. A pointer to a function is another thing.

Upvotes: 0

Oliver Charlesworth
Oliver Charlesworth

Reputation: 272447

There is no need for the cast, assuming input and BLK->buffer are already pointer types (which they really should be).

I can think of two reasons why they're there:

  • The author was paranoid.
  • The author was making it clear that he/she understands that the specific pointer type is going into a "generic" function.

Upvotes: 1

Related Questions