Post by (X) on Mar 14, 2023 15:31:12 GMT 1
When you want to copy a number or count of bytes: cnt from one memory location: src, to another: dst, using GFA's built-in: 'MemCpy dst, src, cnt' statement...
If, instead of the variable cnt, you use a literal: for example '9' or a constant: 'Const k = 9' the 'MemCpy dst, src, cnt' command works as expected.
If you use a variable such as: 'Dim cnt% = 9' or a function such as 'len(a$)', the source and destination are reversed from the specified order!
Da! Da! Daaaaa!!!!!!!!!!!!!!!
It appears MemMove does not suffer from this anomaly.
$Library "gfawinx"
$Library "UpdateRT"
UpdateRuntime ' Patches GfaWin23.Ocx
FullW 1
FontSize = 14
Win_1.OnTop = True
Local a$, b$
Print "Lets try copying the contents of a$ to b$ via memory copy command MemCpy..."
Print "The length or count of byte to copy can be specified by literal: '9' or"
Print "by function 'len(a$)' or Const 'Const k = 9' or variable 'Dim c% = 9'."
a$ = "GFA Basic", b$ = "123456789"
Print
Print "Before..."
Print "a$: "; a$, ", b$: "; b$
MemCpy V:b$, V:a$, 9
Print "Using a literal: '9': OK "
Print "a$: "; a$, ", b$: "; b$
a$ = "GFA Basic", b$ = "123456789"
Print
Print "Before..."
Print "a$: "; a$, ", b$: "; b$
Local lB% = Len(b$) 'Space(9)
Local Const k = 9
MemCpy V:b$, V:a$, k
Print "Using a Const:'k'. This works as described."
Print "a$: "; a$, ", b$: "; b$
a$ = "GFA Basic", b$ = "123456789"
Print
Print "Before..."
Print "a$: "; a$, ", b$: "; b$
MemCpy V:b$, V:a$, lB
Print "Using a variable... FAILS: Copies in reverse order."
Print "a$: "; a$, ", b$: "; b$
a$ = "GFA Basic", b$ = "123456789"
Print
Print "Before..."
Print "a$: "; a$, ", b$: "; b$
MemCpy V:a$, V:b$, lB
Print "Using a variable... OK if src dst order reversed."
Print "a$: "; a$, ", b$: "; b$
a$ = "GFA Basic", b$ = "123456789"
Print
Print "Before..."
Print "a$: "; a$, ", b$: "; b$
MemCpy V:b$, V:a$, Len(b$)
Print "Using a function:'Len(b$)'... FAILS: Copies in reverse order."
Print "a$: "; a$, ", b$: "; b$
a$ = "GFA Basic", b$ = "123456789"
Print
Print "Before..."
Print "a$: "; a$, ", b$: "; b$
MemCpy V:a$, V:b$, Len(b$)
Print "Using(a, function) : 'Len(b$)' OK if src dst order reversed."
Print "a$: "; a$, ", b$: "; b$