l i n u x - u s e r s - g r o u p - o f - d a v i s
Next Meeting:
July 7: Social gathering
Next Installfest:
Latest News:
Jun. 14: June LUGOD meeting cancelled
Page last updated:
2002 Jan 08 12:45

The following is an archive of a post made to our 'vox-tech mailing list' by one of its subscribers.

Report this post as spam:

(Enter your email address)
Re: [vox-tech] what is a bus error
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [vox-tech] what is a bus error

On Tue, Jan 08, 2002 at 11:07:07AM -0800, Ken Bloom wrote:
> Bus errors are a platform dependant thing. They can be caused by problems such as the integer 
> alignment error below, where the computer tries to read a long from a memory location 
> where the processor does not like to find the first byte of a long. This program didn't 
> cause a bus error on my own x86, however it did cause a bus error on one of the HPs in the CS 
> lab.
> #include <iostream>
#include <iomanip>
> using namespace std;
> int main()
> {
>   char * x = new char[16]; // the first byte has suitable alignment for anything
>   for (int t=0;t<16;t++) x[t]=t;
>   cout << reinterpret_cast<long*> (x) << endl;
>   cout << reinterpret_cast<long*> (x+1) << endl;
>   long a = *(reinterpret_cast<long*> (x+1)); 
>   // there are no guarantees about the alignment of the second byte of data
>   // so we could get a bus error here
>   cout << setbase(ios::hex) << a << endl;
>   delete[] x;
>   return 0;
> }

This sucessfully produced an unaligned trap on my Alpha :-). The hardware
trap such unaligned accesses, and the kernel emulates them with some
performance penalty. This allows badly-written software to keep running.

Henry House
The attached file is a digital signature. See <http://romana.hajhouse.org/pgp>
for information.  My OpenPGP key: <http://romana.hajhouse.org/hajhouse.asc>.

Attachment: pgp00011.pgp
Description: PGP signature

LUGOD Group on LinkedIn
Sign up for LUGOD event announcements
Your email address:
LUGOD Group on Facebook
'Like' LUGOD on Facebook:

Hosting provided by:
Sunset Systems
Sunset Systems offers preconfigured Linux systems, remote system administration and custom software development.

LUGOD: Linux Users' Group of Davis
PO Box 2082, Davis, CA 95617
Contact Us

LUGOD is a 501(c)7 non-profit organization
based in Davis, California
and serving the Sacramento area.
"Linux" is a trademark of Linus Torvalds.

Sponsored in part by:
EDGE Tech Corp.
For donating some give-aways for our meetings.