mozilla / cbindgen

A project for generating C bindings from Rust code
Mozilla Public License 2.0
2.43k stars 314 forks source link

Generate flexible array members the c99 way instead of the GNU way #994

Open serge-sans-paille opened 3 months ago

serge-sans-paille commented 3 months ago

There a re three ways to express flexible array members:

  1. char fam[0];

  2. char fam[1];

  3. char fam[];

  4. is the only standard way (in c99, but supported in c++ as an extension), the other two are GNU syntax (still supported in clang though).

Let's generate the standard syntax by default, while leaving it possible to use 1. through struct.gnu_flexible_array_members

Cython only supports the 1. mode.

serge-sans-paille commented 3 months ago

@emilio even if that change is correct from a compiler point of view, it would actually break mozilla code if gnu behavior is of by default because the firefox codebase is making an optimistic use of flexible array members. I guess it's still good to merge this, but with gnu behavior on by default. What do you think?

emilio commented 3 weeks ago

@emilio even if that change is correct from a compiler point of view, it would actually break mozilla code if gnu behavior is of by default because the firefox codebase is making an optimistic use of flexible array members.

Can you elaborate? Do you have an example?