How to properly write the addr function?
pik33
Posts: 2,366
I wanted an integer address instead of a pointer, so I wrote this
function addr(byref v as any) return(cast(ulong,@v)) end function
It works, but every time it is called, I got a warning:
/home/pik33/Dokumenty/GitHub/P2-retromachine/Propeller/Tracker player/player3.bas:380: warning: incompatible pointer types in parameter passing: expected reference to any unknown type but got reference to string pointer to const byte
Comments
It looks like the type checking warnings are just a little too aggressive in that case. I'll try to dial them back to accept it without warning. I think what you wrote is correct.
Now (5.9.8) these warnings disappeared, but I have another one:
statusline(0)=peek(addr(statusline$(0))+(0+amount/8) mod 220)+$71710000
warning: parameter passing discards const attribute from pointer
Although honestly, I think you'd be better off using pointers: that way the compiler can help you find potential errors in the code.
After adding 'const' to the function header, warnings magically disappeared