Skip to content

Some ABIs for zero-sized types are incompatible #59

@teor2345

Description

@teor2345

In C and C++, most zero-sized types are a compiler extension.

Specifically for arrays, the ABIs for arrays and pointers passed directly as arguments are equivalent (arrays decay to pointers). However, arrays of different lengths are incompatible, and passing incompatible lengths causes undefined behaviour.

This can be overcome using type ident[static N] in the argument list. (static N means "an array of at least of length N".)

If C and C++ included zero-sized types in their standards, Rust could implement standards-conforming behaviour.

For more details see:
https://rust-lang.zulipchat.com/#narrow/channel/136281-t-opsem/topic/Non-transitive.20ABI.20compatibility.20in.20C/near/591424586

Metadata

Metadata

Assignees

No one assigned

    Labels

    l-c++Changes that are mainly in C++ (or C)p-semanticsLanguage semantics differencest-problem-statementA description of an interop problem

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions