- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Bus Error in assignment.
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-20-2008 07:00 AM
тАО08-20-2008 07:00 AM
Bus Error in assignment.
There is a piece of code in which when i try to declare and define an integer (uint32_t) it gives me a BUS ERROR.
for example:
uint32_t id = structure.int_variable;
But when i do the same thing by declaring and defining separately in the following manner there is no error.
uint32_t id = 0;
id = structure.int_variable;
I just want to how how does the compiler interpret these statements.
- Tags:
- SIGBUS
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-20-2008 08:09 AM
тАО08-20-2008 08:09 AM
Re: Bus Error in assignment.
a real failing test case, instead of
fragments filled with mysteries like
"structure"?
By the time you explain the problem well
enough that some non-psychic person can see
what you're actually doing, the problem may
become clear to you, too.
> [...] a strange error with aCC C++ compiler.
It's a run-time error, not a compile-time
error, right? Showing actual commands with
actual output can be more helpful than vague
descriptions, too.
> I just want [...]
I'm sure that the compiler can emit the
actual machine code it generates in a form
slightly easier to read than a ".o" file, but
I doubt that that would help you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-20-2008 09:03 PM - edited тАО02-08-2014 08:01 PM
тАО08-20-2008 09:03 PM - edited тАО02-08-2014 08:01 PM
Re: Bus Error in assignment
>I just want to how how does the compiler interpret these statements.
The first is an initialization. The second is an assignment. It they are builtin types, they should do the same thing.
Are you in a thread? A thread stack overflow?
I assume that structure is a static, global, parm or local object? If it is a reference, that could have a bad pointer value.
Can you use gdb to print id and structure?
>Steven: I doubt that that would help you.
It would help me. :-)
What version is your aC++ compiler? What OS version and hardware model?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-21-2008 12:35 AM
тАО08-21-2008 12:35 AM
Re: Bus Error in assignment.
I actually fured out what the problem was.
it starts like this:
in my header file i've declared 2 structures like this:
#pragma pack 2
struct A
{
uint16_t i;
uint32_t j;
};
struct B
{
uint32_t length;
uint32_t id;
uint8_t buf[16];
};
#pragma pack
Now when my function looks like this
void func()
{
A a;
/***** Do Something *****/
B b;
/****** Do Something *****/
int rec_id = b.id; // Line giving SIGBUS
}
Now as far as i'm able to interpret the problem is beacuse of the pragma.
When i declare both the structures with pragma pack 2 i get sizeof(A) as 6 and sizeof(B) as 24.
Now when make their variables from function stack the memory allocated to A is 6 bytes and while making a variable of B compiler starts using the memory address which is just next to A.
Which means B will get 2 bytes from one word rest 20 bytes in next 5 words and next 2 bytes from another word. This thing happens beacuse i've set a "pragma pack 2" for B as well, which is actually not required because B is never going to have any padding.
Thus i just modified the header file to this
#pragma pack 2
struct A
{
uint16_t i;
uint32_t j;
};
#pragma pack
struct B
{
uint32_t length;
uint32_t id;
uint8_t buf[16];
};
n it works fine now. SIGBUS probably was coming because of misalignment.
But the thing is OLD compilers never gave this kinda problem. So is it a compiler bug or is it that this new compiler has added intelligence in it.
I'm running this code on a PA RISC machine and compiled with aCC compiler version
"aCC: HP C/aC++ B3910B A.06.21 "
Sorry again that i provided with limited amount of info. This is also just a sample code written above i can not provide with actual snippet.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-21-2008 01:10 AM - edited тАО02-08-2014 08:00 PM
тАО08-21-2008 01:10 AM - edited тАО02-08-2014 08:00 PM
Re: Bus Error in assignment
>in my header file I've declared 2 structures like this:
There are N things terribly wrong here.
1) This shouldn't abort.
2) Your compiler version doesn't match your architecture.
3) You can't possibly have aCC6's A.06.21, it is still under development.
>while making a variable of B compiler starts using the memory address which is just next to A.
While it could do that, it doesn't have to.
>But the thing is OLD compilers never gave this kinda problem.
What was the old version?
>I'm running this code on a PA-RISC machine and compiled with aCC
The latest aCC3 version is A.03.85.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-21-2008 06:41 PM - edited тАО02-08-2014 08:00 PM
тАО08-21-2008 06:41 PM - edited тАО02-08-2014 08:00 PM
Re: Bus Error in assignment
>while making a variable of B compiler starts using the memory address which is just next to A.
Testing A.03.85 indicates it does that. But I can't duplicate the alignment trap.
What compile options were you using?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-22-2008 08:32 AM
тАО08-22-2008 08:32 AM
Re: Bus Error in assignment.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-22-2008 05:43 PM - edited тАО02-08-2014 08:00 PM
тАО08-22-2008 05:43 PM - edited тАО02-08-2014 08:00 PM
Re: Bus Error in assignment
>I get hold of integration team.
You might have them or you get a hold of me directly.