https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78995

--- Comment #4 from feiz <zhangfei1 at cffex dot com.cn> ---
(In reply to Richard Biener from comment #2)
> static inline void
> rte_memcpy(void *dst, const void *src, size_t n)
> {
>         uintptr_t dstu = (uintptr_t)dst;
>         uintptr_t srcu = (uintptr_t)src;
> 
>     *(uint32_t *)dstu = *(const uint32_t *)srcu;
> 
> this is violating strict aliasing rules as you are copying
> 
> typedef unsigned short  WORD;
> 
> struct TFieldHeader
> {
>     WORD FieldID;
>     WORD Size;
> };

Well, that's right. I add the compile option  -fno-strict-aliasing, and it
works.
To get a better performance, I got the rte_memcpy code from dpdk codes to
replace memcpy in our project.

Very thanks for your  help. And I have one more question about this.

I check some instruction about aliasing, like 
"Strict aliasing is an assumption, made by the C (or C++) compiler, that
dereferencing pointers to objects of different types will never refer to the
same memory location (i.e. alias eachother.)".

I am confused, we always use the following actions, does this safe?

char  buf[1024];
struct A {
     int a;
     int b;
};

struct p * = (struct A*)buf;
p->a =01;
p->b = 02;

Reply via email to