[fpc-devel] New language idea: Unified types (assignment size-compatible types).

Skybuck Flying skybuck2000 at hotmail.com
Sun Jun 19 02:15:15 CEST 2011


Hello,

Here is a new language idea which would make Delphi a bit more friendly:

First the problem:

pointers and longwords are not assignment compatible.

This is pretty much bullshit because they are the same size.

Now the solution, create a new type which has the same size and make it 
"size compatible" with all other types of the same size so for example:

type
    TUnifiedType = unify longword;

This would make the TUnifiedType assigment compatible with all other types 
of the same size.

If this is to broad then the syntax can also be made less broad by having to 
specify all types which are to be considered assignment compatible.

Example of less-broad-syntax:

type
  TUnifiedType = unify longword pointer integer Pinteger Plongword;

The following code would then be possible:

procedure API( ParaUnifiedType : TUnifiedType );

var
    p : pointer;
    t : integer;
    w : longword;
    k : Pinteger;
    z : Plongword;
    e : TunifiedType;
begin
    API( p );
    API( T );
    API( w ):
    API( k );
    API( z );

    e := p;
    p := e;

    // etc
end;

This would also solve some other problems:

var
    I : integer;
    b : byte;
begin
    i := integer(b); // unsafe typecast ! variable overflow ! undetected by 
Delphi XE !
end;

Typecasts for unified types no longer necessary, however unified types have 
automatic size checking so these errors would be caught.

Furthermore writing the api as follows would also not be necessary

API( var data );

^ very unsafe... this would allow more data to be passed in then might be 
expected, leading to parameter overflow !

Therefore conclusion can only be:

Unified types would make programming safer and a whole lot easier without 
all those damned typecasts ! ;) :)

Less remark this could probably come in handy for cuda as well, which has 
slightly different types for example:

host pointer (pointer) vs cuda pointer (longword)

For the unified addressing future of cuda/api the new unified type for 
Delphi would be very welcome ! ;) :)

Bye,
  Skybuck.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-devel/attachments/20110619/ba9759bf/attachment.html>


More information about the fpc-devel mailing list