LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 11-06-2012, 11:31 PM   #1
lohith.nayak
LQ Newbie
 
Registered: Sep 2012
Posts: 12

Rep: Reputation: Disabled
"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,
 
Old 11-08-2012, 08:02 AM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389
@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.

Last edited by druuna; 11-08-2012 at 08:29 AM. Reason: spelling (con't -> don't)
 
Old 11-08-2012, 08:29 AM   #3
johnsfine
LQ Guru
 
Registered: Dec 2007
Distribution: Centos
Posts: 5,286

Rep: Reputation: 1181Reputation: 1181Reputation: 1181Reputation: 1181Reputation: 1181Reputation: 1181Reputation: 1181Reputation: 1181Reputation: 1181
Quote:
Originally Posted by lohith.nayak View Post
...
typedef struct s_1{
...
} s_1_t;
...
s_t s_t_temp;
...
1) When posting code, please use CODE tags to make it more readable.

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.
 
Old 11-08-2012, 09:19 PM   #4
lohith.nayak
LQ Newbie
 
Registered: Sep 2012
Posts: 12

Original Poster
Rep: Reputation: Disabled
Hello,

Ok. I will use CODE TAGS while posting the code.

I used workaround solution.

Code:
S_t s_t_temp;
u32 * ptr = (u32 *)((void *)(&s_t_temp.arr[0]));

/**(u32 *) &s_t_temp.arr[0] = 0;*/
    ptr[0] = 0;
/* *(u32 *) &s_t_temp.arr[4] = 0;*/
    ptr[1] = 0;
/* *(u32 *) &s_t_temp.arr[8] = 0;*/
    ptr[2] = 0;

/* *(u32 *) &s_t_temp.arr[12] = 0;*/
    ptr[3] = 0;

/* *(u32 *) &s_t_temp.arr[16] = htonl((ptr->f <<24) | (ptr->g << 16) | (ptr->h << 8 ) | ptr->i));*/
    ptr[4] = htonl((ptr->f <<24) | (ptr->g << 16) | (ptr->h << 8 ) | ptr->i));
Though it solved the warning, I believe its not an efficient code as casting reduces the performance.
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.

Last edited by lohith.nayak; 11-09-2012 at 02:45 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
What is the argument type required by "kfree"? jason805 Linux - General 2 05-03-2012 12:15 AM
How to solve Warning--entry type for "achemso-control" isn't style-file defined centguy Linux - Software 1 02-29-2012 05:08 AM
"warning: assignment makes integer from pointer without a cast" in C christyyim Programming 4 12-23-2008 11:42 AM
lm-sensors "Warning: the required module is not currently installed" PeeCee-BW Linux - Newbie 1 06-29-2008 01:24 AM
lm-sensors "Warning: the required module is not currently installed" PeeCee-BW Linux - Hardware 2 06-27-2008 12:36 AM


All times are GMT -5. The time now is 03:21 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration