[fpc-pascal] array [boolean] and typecasting fail

David Emerson dle3ab at angelbase.com
Fri Oct 23 03:00:02 CEST 2009


It appears that, in a special case here, the boolean typecast is not 
being done properly/completely, and thus an array is being indexed out 
of bounds. If I compile with rangechecking, I get a rangecheck error; 
without, I get garbage and an EAccessError exception! (trash and crash)

uses math;

type
  rounding_func = function (x : extended) : longint;

const
  t_or_f : array [boolean] of string = ('false', 'true');
  ceil_or_floor : array [boolean] of rounding_func = (@floor, @ceil);

var
  b : boolean;

begin
  b := boolean (6 and 4);
  writeln (t_or_f [b]);
  writeln (ceil_or_floor [b] (2.5));
end.

I was previously using boolean (6 and 4) as the array index directly, 
but I thought the example was easier to read this way, and it still 
crashes for me. Using fpc 2.2.4-3 and (mostly) debian 5.0.3 stable

This smells like a bug to me.

Cheers,
David.




More information about the fpc-pascal mailing list