Shop OBEX P1 Docs P2 Docs Learn Events
[FlexSpin] Filling structs from function calls — Parallax Forums

[FlexSpin] Filling structs from function calls

Hey @ersmith

Does the attached look like it could be a bug? I'm trying to populate a structure using the return from a function. I'm not in the habit of returning instances of structures, but the one I've defined is the same overall size as a long, so I though it may work. The symptom I'm seeing is it doesn't seem to fully write (only the last byte seems to make it in, shown by the debug hexdump). Weirdly, if I add a second debug statement to the function that's populating the structure, it works correctly. NuCode also works correctly here (without the need for uncommenting that second hexdump).

As an alternative, returning a pointer to the same type of structure instead works better with one call, although if I make two separate calls to two different structs, only the second one seems to get written, so it seems like something isn't quite right there, either.

Thanks

Comments

  • ersmithersmith Posts: 6,262

    @avsa242 Yes, that certainly looks like a bug. I can't quite see the root cause, though. At first I thought it was an optimization issue, but it still happens with -O0.

    For now, I would recommend avoiding returning structs, or at least structs that need packing (i.e. that contain words or bytes). I think unpacked structs will probably work, or at least are better tested.

  • Thanks for looking into it! Will do...that seems the easiest way to workaround.

Sign In or Register to comment.