[fpc-devel] void test( void *data ) to procedure test( var data); ? is it safe ?

Hans-Peter Diettrich DrDiettrich1 at aol.com
Tue Jun 21 12:47:22 CEST 2011


Skybuck Flying schrieb:

> Passing real pointers and working with them becomes even more tricky and 
> requires even more stars/asterixes.
> 
> A very bad problem which was easily solved in pascal:
> 
> procedure test( var a : integer );
> begin
>  a := 5;
> end;
> 
> test( a );
> 
> ^ No stupid symbols needed ! ;) Much user friendly and pretty much does 
> the same thing.
> 
> Why make things more difficult then absolutely necessary huh ?! ;) :) =D

What does above code when called with Nil?

While
   test(nil);
may result in a compiler error, the only cure would be to rewrite test as
   procedure test(a: ^integer);

But how would you do that, when the converter decided to use
   procedure test(var a: integer);
instead?

You'll have to *instruct* the converter to use the pointer form, and 
that for *every single* subroutine in the C code.

A converter also cannot determine from a header file, whether the 
implementation does something like this:

int test(int* a)
{
   return (a)?++*a:42;
}

DoDi




More information about the fpc-devel mailing list