Minor Trouble with return values and Function Overloading

General FreeBASIC programming questions.
Post Reply
quinn
Posts: 19
Joined: Jun 27, 2005 0:48

Minor Trouble with return values and Function Overloading

Post by quinn »

I've been futzing around with the new Function Overloading in freebasic, and I've noticed a little trouble that I'm not sure if it's a bug or a necessary evil..

For overloaded functions that return a value, the Quickbasic-style FunctionName = ReturnValue syntax doesn't work, and generates a syntax error at compile time. The C-Style Return ReturnValue syntax does work, however.
Antoni
Posts: 1393
Joined: May 27, 2005 15:40
Location: Barcelona, Spain

Post by Antoni »

You have the PowerBasic style FUNCTION=return_value too...
v1ctor
Site Admin
Posts: 3804
Joined: May 27, 2005 8:08
Location: SP / Bra[s]il
Contact:

Post by v1ctor »

Indeed, it was a bug, changes are in CVS..
quinn
Posts: 19
Joined: Jun 27, 2005 0:48

Post by quinn »

This bug seems to have returned in current CVS, when returning a UDT from an overloaded function.

When you have two overloaded functions that each return a different UDT, the first one will work okay, but the second one generates an "Invalid Data Types" error.. here's an example program:

Code: Select all

Type Vector.2D
	X as Integer
	Y as Integer
End Type

Type Vector.3D
	X as Integer
	Y as Integer
	Z as Integer
End Type

Declare Function Vector.Add  Overload (Position as Vector.2D, Delta as Vector.2D) as Vector.2D
Declare Function Vector.Add (Position as Vector.3D, Delta as Vector.3D) as Vector.3D


Function Vector.Add (Position as Vector.2D, Delta as Vector.2D) as Vector.2D
	Dim Result as Vector.2D
	Result.X = Position.X + Delta.X
	Result.Y = Position.Y + Delta.Y
	Vector.Add = Result
End Function

Function Vector.Add (Position as Vector.3D, Delta as Vector.3D) as Vector.3D
	Dim Result as Vector.3D
	Result.X = Position.X + Delta.X
	Result.Y = Position.Y + Delta.Y
	Result.Z = Position.Z + Delta.Z
	Vector.Add = Result
End Function
v1ctor
Site Admin
Posts: 3804
Joined: May 27, 2005 8:08
Location: SP / Bra[s]il
Contact:

Post by v1ctor »

True, i'll have to make some modifications to the name mangling when UDT's are used too (when they are the only arguments), they will conflict using the current code.

I'll commit the changes ASAP.


EDIT: fixed, changes are in the CVS repository, it may take a while to SF.net update the anonymous access.
quinn
Posts: 19
Joined: Jun 27, 2005 0:48

Post by quinn »

Excellent! It compiles fine now.. this is so much nicer than passing an extra argument by reference.
Post Reply