Pass a variable "byref" or pass its pointer "byval" to a procedure is fonctionally equivalent under the hood:Because when you pass a variable "byref", the compiler passes the address of the variable (a pointer) "byval", and it adds some code for dereferencing the passed pointer when you use the reference in the procedure body.

By cons, passing "byval as any ptr" allows to pass variables of different types to a same procedure, but in order to use these variables, the "any ptr" pointer must be converted to the right type before dereference it in the procedure body.

Expanding on what FXM said: In the code you showed you are: - in the first case passing the address of variable 'mytype' to the procedure. - in the second case FB defaults to ByRef for UDT's, so again you are passing the address of 'mytype' to the procedure.

If you had run the code it would have been obvious. Please run the code and see for yourself.In the following code the final print results in 43 not 42. Thus somesub2() has changed the variable contents.

For me, I find it typically depends on how I create the object that I am working with:DIM x as T '' use BYREF as T parametersDIM x as T PTR = new T '' use BYVAL as T PTR parameters

It's great that fbc supports pointers; it makes many data structures like lists and trees easy to work with. Except that when using pointers, you should also expect to get a NULL (zero) pointer and deal with that.

With dkl's work on BYREF variables, and BYREF function returns, not using pointers is also appealing. I find that using BYREF and . DOT member access tends to make the code a little easier to read and don't have to worry about @, *, -> operators.

Expaning on fxm's comment, I think more correctly:BYREF as T is closer toBYVAL as T CONST PTR.

I always try to give the CONST-ness of parameters consideration when declaring routines; fbc can give catch a number of programming errors if you let it know how you expect a parameter to change (or not).

coderJeff wrote:With dkl's work on BYREF variables, and BYREF function returns, not using pointers is also appealing. I find that using BYREF and . DOT member access tends to make the code a little easier to read and don't have to worry about @, *, -> operators.

I fully agree.It's why I'm waiting impatiently the continuing of development around references:- adding the capacity to define arrays (static or dynamic) of references,- adding the capacity to declare member references (variables and arrays) in UDTs,so that they can also replace the use of pointers in these cases.

'create an array of points at box corners, return the pointerFunction points.box(x1 As long,y1 As long,x2 As long,y2 As long) As points Ptr Dim As long dx=(x2-x1),dy=(y2-y1) Swap dx,dy:dx=-dx Static p(4) As points p(1)=Type(x1-dx/2,y1-dy/2) p(2)=Type(x1+dx/2,y1+dy/2) p(3)=Type(x2+dx/2,y2+dy/2) p(4)=Type(x2-dx/2,y2-dy/2) p(0)=Type<points>((x1+x2)\2,(y1+y2)\2) 'p(0) reserved for the the centre EndOfPointer=Ubound(p) message=__function__ Return @p(0)End Function'getter setter function (instead of property)Function points.set(c As Ulong,FillFlag As Byte,byref pt as points ptr) Byref As points Ptr Static As points Ptr p',pt ' pt=new points Function= p 'get If p Then 'set For n as long =1 To EndOfPointer If n=1 Then Pset(p[n].x,p[n].y),c Else line -(p[n].x,p[n].y),c if n= EndOfPointer then line (p[n].x,p[n].y)- (p[1].x,p[1].y),c ' close Next pt->x=p[0].x 'retrieve and return the centroid pt->y=p[0].y function=pt 'return the centroid If FillFlag Then Paint(p[0].x,p[0].y),c,c circle(pt->x,pt->y),3,,,,,f End If delete p p=0End Function

Function points.set(c As Ulong,FillFlag As Byte,byref pt as points ptr) Byref As points Ptr Static As points Ptr p',pt ' pt=new points Function= p 'get If p Then 'set For n as long =1 To EndOfPointer If n=1 Then Pset(p[n].x,p[n].y),c Else line -(p[n].x,p[n].y),c if n= EndOfPointer then line (p[n].x,p[n].y)- (p[1].x,p[1].y),c ' close Next pt->x=p[0].x 'retrieve and return the centroid pt->y=p[0].y function=pt 'return the centroid If FillFlag Then Paint(p[0].x,p[0].y),c,c circle(pt->x,pt->y),3,,,,,f End If' delete p' p=0End Function

It wasn't so much to fix anything, but to show the compile errors.I don't use -gen gcc much, so I am surprised to see the (non freebasic) compile log/errors.(Fbide)In essence, you would have to get the c code, read the errors in the compiler log, and try and figure out where these errors are in the basic code.