Shop OBEX P1 Docs P2 Docs Learn Events
How to properly write the addr function? — Parallax Forums

How to properly write the addr function?

pik33pik33 Posts: 2,366
edited 2022-01-27 22:01 in BASIC (for Propeller)

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.

  • pik33pik33 Posts: 2,366

    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

  • function addr(byref v as const any)
      return(cast(ulong,@v))
    end function
    

    Although honestly, I think you'd be better off using pointers: that way the compiler can help you find potential errors in the code.

  • pik33pik33 Posts: 2,366

    After adding 'const' to the function header, warnings magically disappeared :)

Sign In or Register to comment.