How to deal with "dereferencing type-punned pointer will break strict-aliasing rules" when compiling C?

1. Examples are as follows:

char my_array[10];

*(int *)my_array = 0xaabbccdd;

 

2. Modify the following to solve this problem:

char my_array[10];

int tmp = 0xaabbccdd;

memcpy(my_array, &tmp, sizeof(tmp));

Guess you like

Origin www.cnblogs.com/dakewei/p/12708752.html