News for hackers. Stuff that matters.
Re:Wrong optimization with aliasing by derefr on Tuesday February 16, 2016 @06:56PM (#11114081)
> How do you interpret the above paragraph?

It says that...

   int a = 5;
   char *b = memcpy(malloc(sizeof(a)), &a, sizeof(a));
...should fail. The memcpy(3) src is &a, a pointer-to-int; the memcpy(3) dest is a pointer-to-void (i.e. an untyped pointer) from malloc(3). Thus, memcpy(3)'s return type should be a pointer-to-int.
Re:Wrong optimization with aliasing by pklausler on Tuesday February 16, 2016 @07:00PM (#11114094)
It's being assigned a pointer-to-void, yes?
Re:Wrong optimization with aliasing by derefr on Tuesday February 16, 2016 @07:03PM (#11114111)
It is, yes, according to the typespec of memcpy(3). But according to the standard, it shouldn't be; it should be returning a [whatever-type-src-was-passed-in-as]. I have doubt that there's any way in C to specify variable return type like that—but the C standard, AFAIK, doesn't require that memcpy(3)—or anything else from libc—be implementable in C. It can be, as Lisp would put it, a "special form."

To get an implicit pointer-to-char-typed buffer out of memcpy(3), you should have to attach the malloc(3)-returned buffer to a pointer-to-char-typed variable (or give it an explicit cast) to give it a type, and then pass it in as dest.