You are here:

C/CPU exception errors in C programming

Advertisement


Question
Narendra,

I have doubts on the following:

1. misaligned memory access - provide me a C program which does this error and tell me how you fix that.

2. Bus error & segmentation violation - what are these terms? Any C program example for these and how you fix them.

Best Regards,
Rajesh

Answer
I don't have any sample programs to show those errors.
But, it is easy to produce a "Segmentation Fault" program.

Compile and execute this program:

main()
{
   int *i = NULL;

   *i = 10;
}

Segmentation fault is the most frequently acquinted problem. It occurs because your program has tried to write into readonly areas of its address space.
Bus error occurs due to error in the address bus.
I haven't heard about "Mis-Alligned memory access" error.

-ssnkumar

C

All Answers


Answers by Expert:


Ask Experts

Volunteer


Narendra

Expertise

I can answer questions in C related to programming, data structures, pointers and file manipulation. I use Solaris for doing C code and if you have questions related to C programming on Solaris, I will be able to help better.

Experience

6.5

Organizations belong to
Sun Microsystems

Awards and Honors
Brain Bench Certified Expert C programmer.
Advanced System Software Certified

©2012 About.com, a part of The New York Times Company. All rights reserved.