Discussion:
New language idea: Unified types (assignment size-compatible types).
(too old to reply)
Skybuck Flying
2011-06-19 00:12:14 UTC
Permalink
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.
Dr Engelbert Buxbaum
2011-07-06 02:32:17 UTC
Permalink
Post by Skybuck Flying
Hello,
pointers and longwords are not assignment compatible.
This is pretty much bullshit because they are the same size.
Turbo Pascal had absolute variables for this, that is, two variables of
different type but same size, that shared the same adress in memory. So
for example it was possible to generate universal stacks, which could
accept data of any type. The procedures and functions operating on the
stack (push and pop) got told the size of the stored data with SizeOf().

Another use was to write functions (rather than procedures) for complex
numbers. The trick was to pass strings, but inside the functions treat
them as records of two floating point numbers.
Skybuck Flying
2011-07-06 04:45:07 UTC
Permalink
Delphi still has absolute directive/keyword.

Last time I tried it (probably delphi 2007) it was bugged, so never used it
since ;)

Bye,
Skybuck.

Loading...