void * in ANSC

C

CBFalconer

Walter said:
How do you arrive at that number? memcpy() does not define
the behaviour if the fields overlap. memmove() is the function
.... snip ...

There is a from and a to parameter. They have restrict applied, so
they are different. Each points to a 42 byte area, which is either
examined or modified. 42 + 42 is roughly equal to 84. In base 10.

7.21.2.1 The memcpy function

Synopsis
[#1]
#include <string.h>
void *memcpy(void * restrict s1,
const void * restrict s2,
size_t n);
Description
[#2] The memcpy function copies n characters from the object
pointed to by s2 into the object pointed to by s1. If
copying takes place between objects that overlap, the
behavior is undefined.

Returns
[#3] The memcpy function returns the value of s1.

Please don't strip attributions for any material you quote.
 
A

Army1987

Peter said:
How many bytes does the following access?

memcpy(foo, bar, 0);

If it's none, then why should *memcpy(foo, bar, 0) be
any different? If it isn't different, then why should
dereferencing a volatile void pointer be any different?
Ok, another example:

volatile struct incomplete *foo = a_function_returning_a_struct_pointer();
*foo;
How many bytes does the statement access?
 
H

Harald van Dijk

Ok, another example:

volatile struct incomplete *foo =
a_function_returning_a_struct_pointer(); *foo;
How many bytes does the statement access?

The behaviour is undefined, and no sane behaviour could be defined. Two
compilers I've tried generate an error, one warns and doesn't access any
bytes. (A fourth has problems with respecting the volatile keyword and
doesn't access any bytes even if the type is complete, but let's ignore
that one.) Quoting 6.3.2.1p2:
"Except when it is the operand of the sizeof operator, the unary &
operator, the ++ operator, the -- operator, or the left operand of the .
operator or an assignment operator, an lvalue that does not have array
type is converted to the value stored in the designated object (and is
no longer an lvalue). If the lvalue has qualified type, the value has the
unqualified version of the type of the lvalue; otherwise, the value has
the type of the lvalue. If the lvalue has an incomplete type and does
not have array type, the behavior is undefined."

This applies to struct incomplete but not to void *, because an
expression of type void is by definition never an lvalue, even if it is
the result of the unary * operator.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top