2

Using a Sample Program with Segmentation Violation

A segmentation violation occurs when your program tries to reference memory outside your address space. The operating system detects this action and generates an error message. Following is an example program, SegViol.p, which contains a segmentation violation:

program SegmentationViolation; type

Pinteger = ^integer;

procedure ErrorInHere; var

IntVar: integer;

NullPtr: Pinteger; begin

NullPtr := nil;

{Next statement causes a SEGV } IntVar := NullPtr^;

end;

procedure Call1; procedure Call2; begin

ErrorInHere;

end; begin

Call2;

end;

begin Call1;

end.

Compiling and Running the Program

When you compile and run the program, you receive output similar to the following. The first line indicates the name of the offending signal—in this case, a segmentation violation.

14

Pascal 4.0 User’s Guide