[fpc-pascal] Is it possible to redefine FreePascal types?
Howard Page-Clark
hdpc at talktalk.net
Wed Nov 21 21:04:47 CET 2012
On 21/11/12 7:49, Kenneth Cochran wrote:
> Yes.
>
> type newString = type string;
>
> Any function that accepts newString as a parameter will cause a
> compilation error if you try to pass a normal string. You'll have to
> cast it to newString first.
This is not the case, as the following program demonstrates. The
compiler does not even blink.
program Project1;
{$mode objfpc}{$H+}
type TnewString = type string;
function NewStringFn(ns: TnewString): integer;
var c: Char;
begin
Result := 0;
for c in ns do
if (c<>#0) then inc(Result);
end;
var s:string = 'ansistring';
ns:TnewString = 'new string';
begin
writeln('The new string length is ',NewStringFn(ns));
writeln('The old string length is ',NewStringFn(s));
end.
More information about the fpc-pascal
mailing list