Consider this code in C ++
struct Base { std::int64_t x; std::int64_t y; }; static_assert(sizeof(Base) == 16, "Base not of size 16!"); struct Derived : Base { std::int32_t z; }__attribute__((packed)); static_assert(sizeof(Derived) == 20, "Derived not of size 20!");
clang considers this code valid when gcc causes the second static_assert to run. ("It is not made from size 20!). If I add an attribute packed into the database, then this is fine in compilers as well. Does anyone know which one is right and why?
Both are correct.
( ), , , , static_assert -, ( ) - , .
static_assert
__attribute__((packed)) (-), , , , . , , (/ ). , .
__attribute__((packed))
, .
, , , , , . , , . , .
Source: https://habr.com/ru/post/1653497/More articles:for loop to retrieve header for data frame in pandas - pythondidReceiveLocalNotification does not receive a call after using UNUserNotificationCenter - iosHow to generate application version using Spring Boot, Gradle, Semantic Versioning and Jenkins - spring-bootJavaFX - reusable FXML component - javaAngularJS + ion-list ng-repeat not Population List - javascriptThe best way to add a method to all eloquent models - eloquentWhy is VC ++ compiling code, but clang not? - c ++DbFailOnError SQL Server datetime error for time values - datetimeHow Apple knows if an application is uninstalled - iosParse a string into a command and arguments in JavaScript - javascriptAll Articles