[fpc-pascal] Constants in generics
    Ryan Joseph 
    ryan at thealchemistguild.com
       
    Tue Jan  8 17:34:03 CET 2019
    
    
  
Yesterday I discovered I wasn’t doing proper range checking for ordinal constants so for example, a generic with “const U: byte” could be specialized as <1000>. We want ordinal constants to respect range checks right?
I made a little utility function which works in most cases but I don’t think it’s correct and more importantly this function probably already exists in the compiler.
    function compare_orddef_by_range(param1,param2:torddef): boolean;
      var
        orddef1,orddef2:tdef;
      begin
         range_to_type(param1.low,param1.high,orddef1);
         range_to_type(param2.low,param2.high,orddef2);
         result:=compare_defs(orddef1,orddef2,nothingn)>=te_convert_l1;
      end;
Is there an existing function for this or a better way to do it?
Regards,
	Ryan Joseph
    
    
More information about the fpc-pascal
mailing list