Shop OBEX P1 Docs P2 Docs Learn Events
array-to-pointer decay? — Parallax Forums

array-to-pointer decay?

Seems that when you have buffer[256] and want the address of the first element, have to use @buffer as it is now. How big a change would it be to have the C++ array-to-pointer decay where can use just buffer instead of @buffer?

Comments

  • Very. IIRC there's actually no distinction between an array and a scalar value in the spin compiler.
    And of course all the existing code will explode.

  • RaymanRayman Posts: 16,235

    So “buffer” returns the first element of the array? Would any existing code actually use it that way?

  • JonnyMacJonnyMac Posts: 9,788
    edited 2026-04-04 22:47

    Yes. You could, but it's probably better practice to use buffer[0].

  • In the orignal PropTool Spin1 compiler (and derivatives like openspin and the Spin Tools compiler), it's actually better to write just buffer instead of buffer[0] because the latter will actually push a zero to the stack and then do an indexed access (slower and an extra byte of code). It's very literal like that. flexspin bytecode will constant fold indexed accesses like that (IIRC with any constant index). Not sure what PNut Spin2 does.

  • RaymanRayman Posts: 16,235

    Wouldn’t code with any new features require the version brackets? Seems that would prevent old code from breaking?

Sign In or Register to comment.