The brackets inside a macro are important.
I had just about given up with this macro to simulate memcpy from crt.bi
As a last resort, before binning everything, I bracketed off the macro.
And then, it seemed to work:
Code: Select all
#include "crt.bi"
#macro memcpyFB(dest,src,size)
scope
var sz=(size)/sizeof(*(src))
for n as long=0 to sz-1
(dest)[n]=(src)[n]
next
end scope
#endmacro
'udt test
type udt
as integer i
as string s
as long a(45)
end type
dim as udt x(123),y(123),z(123)
x(25).i=13
x(25).s="Hello"
x(25).a(13)=78
memcpyFB(@y(0),@x(0),(ubound(x)-lbound(x)+1)*sizeof(x))
print y(25).i,y(25).s,y(25).a(13),"freebasic"
memcpy(@z(0),@x(0),(ubound(x)-lbound(x)+1)*sizeof(x))
print z(25).i,z(25).s,z(25).a(13),"c runtime"
'===============
'array test
dim as string a(3,8),b(3,8),c(3,8)
dim as long size=((ubound(a,1)-lbound(a,1)+1)*(ubound(a,2)-lbound(a,2)+1)*sizeof(string))
a(3,8)="FreeBASIC"
memcpyFB(@b(0,0),@a(0,0),size)
print b(3,8)
a(3,8)="C runtime"
memcpy(@c(0,0),@a(0,0),size)
print c(3,8)
sleep