Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ISO C structs with different tags are incompatible #6791

Open
Humm42 opened this issue Feb 2, 2024 · 2 comments
Open

ISO C structs with different tags are incompatible #6791

Humm42 opened this issue Feb 2, 2024 · 2 comments

Comments

@Humm42
Copy link

Humm42 commented Feb 2, 2024

[diff.basic]/5 states:

C allows “compatible types” in several places, C++ does not. For example, otherwise-identical struct types with different tag names are “compatible” in C but are distinctly different types in C++.

That hasn’t been true for C for quite a while now.

@frederick-vs-ja
Copy link
Contributor

Looks like already false in C99 (perhaps changed by WG14 N522).

@frederick-vs-ja
Copy link
Contributor

frederick-vs-ja commented Feb 2, 2024

Perhaps we should say an enum type is compatible with its enum type in C, but not in C++.

int main(void) {
  enum et { v } e = v;
  unsigned int *p = &e; // valid in C if the underlying type of enum et is unsigned int, invalid in C++
}

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

No branches or pull requests

2 participants