Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

8
  • stackoverflow.com/questions/621616/… Empty struct is larger in C++ than in C. Commented Jan 4, 2024 at 11:33
  • @Basilevs: I don't believe that's accurate. An array of empty structs in C has the same problem as in C++. C++ allows it to be zero in a few corner cases (e.g., use as a base class), but those don't have direct analogs in C. Commented Jan 4, 2024 at 15:15
  • this was the case in 2012, when I was porting code from C++ for a Linux device driver. Commented Jan 4, 2024 at 15:37
  • @Basilevs: If so, it was almost certainly a matter of the C compiler not conforming to the standard, at least with the flags you used. Consider code like struct empty{}; struct empty e[2]; if (&e[0] == &e[1]) printf("the compiler is broken\n"); Those pointers are required to compare as not-equal in both C and C++, which means empty has a minimum size of 1 in both. Commented Jan 4, 2024 at 15:41
  • There is no such requirement Commented Jan 4, 2024 at 15:43