"warning: Cast increases required alignment of target type [-Wcast-align]
Hello,
I am porting code from (x86, ppc) platform to ARM-15. It uses LINUX os, GCC compiler. Goal is to write platform independent code. When I compile my code (on ARM), I am getting following warning, "Cast increases required alignment of target type [-Wcast-align]". Code looks like this. typedef struct s_1{ u32 a:24; u32 r_1:8; u32 b:25; u32 r_2:2; u32 c:3; u32 r_3:2; u32 r_4:16; u32 d:16; u32 r_5:32; u8 arr[32]; } s_1_t; typedef struct s_2 { u32 a; u32 b; u16 c; u16 d; u16 e; u8 f; u8 g; u8 h; u8 i; } s_2_t; function(s_2_t * ptr) { s_t s_t_temp; *(u32 *) &s_t_temp.arr[0] = 0; *(u32 *) &s_t_temp.arr[4] = 0; *(u32 *) &s_t_temp.arr[8] = 0; *(u32 *) &s_t_temp.arr[12] = 0; *(u32 *) &s_t_temp.arr[16] = htonl((ptr->f <<24) | (ptr->g << 16) | (ptr->h << 8 ) | ptr->i)); } I am getting warning on each assignment statements. I tried using "__attribute__ ((aligned (4))) " at arr[32]. But still getting this warning. Please let me know if I am posting a thread in wrong place. Could you please let me know other options to resolve this??? Thanks in advance, |
@lohith.nayak: You've marked this as SOLVED, but you don't provide an answer. Can you provide the solution so others can benefit from it?
Anyway: Off the zero-reply list. |
Quote:
2) Try harder to make the portion of code you post consistent with the code you tested when getting the symptoms you reported. In this case, you seem to have messed up the name of that type (s_1_t vs. s_t) in whatever edits you thought were necessary to cut down from the code you tested to the portion you wanted to post. It is best to cut down to a small complete program that demonstrates the same symptom. Anything complete enough to let others test and duplicate the same symptom is a much better basis for us giving you a good answer. |
Hello,
Ok. I will use CODE TAGS while posting the code. I used workaround solution. Code:
I read in some article its good to define u32 in struct member and then casting it back to u8 whenever is necessary. If anybody suggest any solution, I would be very thankful. Thanks. |
All times are GMT -5. The time now is 04:49 AM. |