Extern struct cannot hold vector since 0.17?

Hello,

I guess this is a 0.17 change? I

error: extern structs cannot contain fields of type '@Vector(2, f32)'
// I understand the following:
note: vectors have no guaranteed in-memory representation
// But I didn't seen in the release notes if there was a prefered way to handle these?

On the ObjectiveC side of my codebase, It is defined as vector_float2 in that case.

I have no idea of conversion will be costless on either zig or objc side ?

Technically this was already true in previous versions, it just wasn’t enforced.
You can fix it by using [2]f32 align(8) (assuming that the ObjectiveC side is also aligned to 8 bytes), you may need to coerce it to Vec2f with @as in some of the use cases though.

Extern structs are basically a C struct and because of that its fields must have a guaranteed in memory representation (which @Vector don’t). vector_float2 is defined as:

// https://developer.apple.com/documentation/simd/vector_float2?language=objc
typedef simd_float2 vector_float2; 
// https://developer.apple.com/documentation/simd/simd_float2?language=objc
typedef float __attribute__((ext_vector_type(2))) simd_float2; 

and ext_vector_type attribute adds some syntactic sugars to a vector type:

This type is created using attribute((ext_vector_type(n)), where “n” is the number of elements. Unlike vector_size, ext_vector_type is only allowed on typedef’s. This class enables syntactic extensions, like Vector Components for accessing points (as .xyzw), colors (as .rgba), and textures (modeled after OpenGL Shading Language).

As far as I can tell you should be fine with defining it as stated above, you can read more about them in here.

Thank you both! I need to gets hands on to see how this will go.

https://codeberg.org/ziglang/zig/issues/36082 is the relevant issue to follow for first-class vector support in C ABI interop.