pointer as function result

Beta Testing discussion on mikroPascal.
Post Reply
Author
Message
janni
Posts: 5373
Joined: 18 Feb 2006 13:17
Contact:

pointer as function result

#1 Post by janni » 12 Aug 2008 14:55

I know that function result is supposed to be of simple type but, as the compiler accepts pointer as a result, someone might be misled that it works. It would naturally be useful, if it worked :) - for the moment compiler does something rather illogical, though.

This simple program

Code: Select all

var bb:byte;
    pst: ^byte;

function aaa(stl:^byte): ^byte;
 begin
  result:=stl;
 end;
 
BEGIN
  pst:=aaa(@bb);
END.
produces code for the aaa function

Code: Select all

$033A	$	_aaa:
;testv8.ppas,25 :: 			begin
;testv8.ppas,31 :: 			result:=stl;
$033A	$C083	FFE1	MOVFF	_aaa_local_result, FSR1Ptr
$033E	$C084	FFE2	MOVFF	_aaa_local_result+1, FSR1Ptr+1
$0342	$C081	FFE6	MOVFF	FARG_aaa, POSTINC1
$0346	$C082	FFE6	MOVFF	FARG_aaa+1, POSTINC1
$034A	$	testv8_L_1:
;testv8.ppas,32 :: 			end;
$034A	$C083	F000	MOVFF	_aaa_local_result, STACK_0
$034E	$C084	F001	MOVFF	_aaa_local_result+1, STACK_0+1
$0352	$0012	    	RETURN
that sends the function argument to undefined address (contained in uninitialised functin result), instead of simply copying it into the result.

Would it be hard to fix it so that pointer result could be used (most satisfying solution :D ) or make the compiler to produce a warning?

Post Reply

Return to “mikroPascal Beta Testing”