Skip to content

Conversation

@spookee0
Copy link
Contributor

Got this error when my struct became 8-aligned:

❯ zig build
install
└─ compile exe fw.elf Debug thumb-freestanding-eabihf 1 errors
<cache>/zigfsm-0.2.0-9VW4ufo6AQDk-HL7-JMc-XNgKRXzkeoNdDzrMtg8eF45/src/main.zig:647:16: error: @fieldParentPtr increases pointer alignment
        return @fieldParentPtr(field_name, interface_ref);
               ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
<cache>/zigfsm-0.2.0-9VW4ufo6AQDk-HL7-JMc-XNgKRXzkeoNdDzrMtg8eF45/src/main.zig:647:16: note: '*align(4) Bldc' has alignment '4'
<cache>/zigfsm-0.2.0-9VW4ufo6AQDk-HL7-JMc-XNgKRXzkeoNdDzrMtg8eF45/src/main.zig:647:16: note: '*Bldc' has alignment '8'
<cache>/zigfsm-0.2.0-9VW4ufo6AQDk-HL7-JMc-XNgKRXzkeoNdDzrMtg8eF45/src/main.zig:647:16: note: use @alignCast to assert pointer alignment
referenced by:
    onTransition: src/Bldc.zig:97:50
    make [inlined]: <cache>/zigfsm-0.2.0-9VW4ufo6AQDk-HL7-JMc-XNgKRXzkeoNdDzrMtg8eF45/src/main.zig:656:44
    init [inlined]: src/Bldc.zig:37:46
    bldc: src/Starter.zig:3:34
    8 reference(s) hidden; use '-freference-trace=12' to see all references
error: the following command failed with 1 compilation errors:
<toolchain>/zig build-exe ...

Found this: https://ziggit.dev/t/is-aligncast-necessary-with-fieldparentptr/11902/2
and this is my case (32-bit cortex-m4)

With @alignCast my code compiles and works as before

@cryptocode
Copy link
Owner

Good catch, thanks!

@cryptocode cryptocode merged commit d4438aa into cryptocode:main Oct 30, 2025
@spookee0 spookee0 deleted the fix/field_parent_ptr_alignment branch October 30, 2025 12:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants