Zhenfeng, As Sid pointed out, the bus error is due to access of int32 data at non word aligned address.
You have turned on structure packing with the #pragma directive. If this was not done, the compiler would have padded 3 bytes between the char 'm' and int 'data'. In that case, the int 'data' would have been word aligned. You can use #pragma pack(push, 4) to resolve the problem. Best Regards, Anand Balagopalakrishnan Texas Instruments India -----Original Message----- From: davinci-linux-open-source-bounces+anandb=ti....@linux.davincidsp.com [mailto:davinci-linux-open-source-bounces+anandb=ti....@linux.davincidsp.com] On Behalf Of Heroor, Siddharth Sent: Monday, April 27, 2009 11:30 AM To: zhenfeng ren; [email protected] Subject: RE: when port a software , bus error Hi, On Arm, you can access only word aligned data. To access a 32 bit value, the address needs to be 32 bit aligned etc.. If the data is not aligned, then a bus error is thrown. I'm guessing that its because of the char m, data[] will not be aligned in _test_c. Thanks and Regards, Sid +91-80-25099294 -----Original Message----- From: zhenfeng ren [mailto:[email protected]] Sent: Saturday, April 25, 2009 8:44 AM To: [email protected] Subject: when port a software , bus error hi, everyone: Just like the code as below: 1 #include <algorithm> 2 #include <stdio.h> 3 4 #pragma pack(push, 1) 5 typedef struct _test_c 6 { 7 char m; 8 int data[10]; 9 }test_c; 10 #pragma pack(pop) 11 12 int main() 13 { 14 printf(" sizeof test_c is %d \n", sizeof(test_c)); 15 test_c test; 16 for(int i=0; i<10; i++) 17 test.data[i] = 9-i; 18 //int data[10]={9, 8, 7, 6, 5, 4, 2, 3, 1 , 0}; 19 std::sort(test.data, test.data+10); 20 21 return 1; 22 } This code can work on X86, but cause bus error runing on Davinci(My board is DM6446, GCC 3.4) . I know the problem is: std::sort(test.data, test.data+10); test.data is not 4-Bytes aligned. The software I want to port uses structs liking "test_c" a lot. Could anyone give me some advice ? -- Thanks, Zhenfeng Ren _______________________________________________ Davinci-linux-open-source mailing list [email protected] http://linux.davincidsp.com/mailman/listinfo/davinci-linux-open-source _______________________________________________ Davinci-linux-open-source mailing list [email protected] http://linux.davincidsp.com/mailman/listinfo/davinci-linux-open-source
