Bus Error

M

maths_fan

Did anyone meet this kind of error? In which situation? If someone
knows some examples, which make this error - I'll be very thankful!
 
Z

Zygmunt Krynicki

Did anyone meet this kind of error? In which situation? If someone
knows some examples, which make this error - I'll be very thankful!

AFAIK it has to do with unaligned access to memory (on some processors)

Example (untested):

char buf [sizeof (int) * 2];
int *ptr = (int*)(buf+1);
*ptr = 1234; /* this might cause bus error */


HTH
 
M

maths_fan

Zygmunt Krynicki said:
Did anyone meet this kind of error? In which situation? If someone
knows some examples, which make this error - I'll be very thankful!

AFAIK it has to do with unaligned access to memory (on some processors)

Example (untested):

char buf [sizeof (int) * 2];
int *ptr = (int*)(buf+1);
*ptr = 1234; /* this might cause bus error */


HTH

Don't you know the reason? What kind of architecture should have the
processor for having this problem? I am more than sure, that this
problem doesn't occur in Intel processors (not quite sure, but, it's
most likely on AMD as well.)
 
J

Juergen Heinzl

Zygmunt Krynicki said:
Did anyone meet this kind of error? In which situation? If someone
knows some examples, which make this error - I'll be very thankful!

AFAIK it has to do with unaligned access to memory (on some processors)

Example (untested):

char buf [sizeof (int) * 2];
int *ptr = (int*)(buf+1);
*ptr = 1234; /* this might cause bus error */


HTH

Don't you know the reason? What kind of architecture should have the
processor for having this problem?
[-]
Try on your nearest SPARC.
I am more than sure, that this problem doesn't occur in Intel
processors (not quite sure, but, it's most likely on AMD as well.)
[-]
Data access becomes slower, but it does not cause bus errors. Still
I've seen bus errors on Intel machines, too, though due to other
things gone awfully wrong.

Dereferencing an invalid pointer can result in a SIGBUS, too, but
again it depends on the actual system.

Ta',
Juergen
 
E

Eric Sosman

maths_fan said:
Did anyone meet this kind of error? In which situation? If someone
knows some examples, which make this error - I'll be very thankful!

This is Question 16.8 in the comp.lang.c Frequently
Asked Questions (FAQ) list

http://www.eskimo.com/~scs/C-faq/top.html

.... and it's understandable that you missed it when you
first scanned the FAQ, because the question synopsis in
the index doesn't mention "bus error" at all. Indices
are always tricky to produce: make them 100% complete
and they're bigger than the material indexed, condense
them and somebody has trouble finding something. That's
why it's a good idea to *read* the FAQ instead of simply
scanning it.
 
M

Mark A. Odell

(e-mail address removed) (maths_fan) wrote in

Did anyone meet this kind of error? In which situation? If someone
knows some examples, which make this error - I'll be very thankful!

AFAIK it has to do with unaligned access to memory (on some processors)

Example (untested):

char buf [sizeof (int) * 2];
int *ptr = (int*)(buf+1);
*ptr = 1234; /* this might cause bus error */

Don't you know the reason? What kind of architecture should have the
processor for having this problem?

<OT>
Many, many RISC architectures have this feature (not problem). E.g. MIPS,
PowerPC, etc. Welcome to the RISC world where we align our data objects on
proper boundaries. By the way, what does this have to do with the C
language? </OT>
 
J

Jarno A Wuolijoki

char buf [sizeof (int) * 2];
int *ptr = (int*)(buf+1);
*ptr = 1234; /* this might cause bus error */

Don't you know the reason? What kind of architecture should have the
processor for having this problem? I am more than sure, that this
problem doesn't occur in Intel processors (not quite sure, but, it's
most likely on AMD as well.)

<ot>Actually it can be made to happen even on x86. There's a bit
in eflags called alignment check for that purpose</>
 
M

Mike Wahler

maths_fan said:
Did anyone meet this kind of error?

Yes, one day I wanted to go from Kirkland, WA to
Seattle. But I boarded the bus for Everett by
mistake. Bus error, as well as a money leak.
In which situation?

When not paying close enough attention to what one
is doing, whether writing a program, or trying to
travel to a particular destination.
If someone
knows some examples, which make this error - I'll be very thankful!

Those platforms which can have 'bus errors' typically
do when a program invokes 'undefined behavior' as in
dereferencing a null or invalid pointer, creating
'unaligned' objects, etc.

If you have a small compilable code example which give
the bus error, post it here, and we'll help track down
the problem.

-Mike
 
C

clord

I take the wrong bus all the time. My boss gets pissed, cuz I'm always
late for work, but god dammit, this is off topic and while we're off
topic, do you know where I can get a good deal on a spatula? I'm in dire
need.

CLord.
 
N

Neil Cerutti

I take the wrong bus all the time. My boss gets pissed, cuz
I'm always late for work, but god dammit, this is off topic and
while we're off topic, do you know where I can get a good deal
on a spatula? I'm in dire need.

Spatula City.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,562
Members
45,038
Latest member
OrderProperKetocapsules

Latest Threads

Top