Код: Выделить всё
#include
#include
// 3rd-part C99 API
extern "C" {
struct Foo {
int length;
int array[];
};
void do_something(struct Foo*);
}
// My C++ code
auto bar() {
auto length = 4;
std::byte buffer[sizeof(Foo) + length * sizeof(int)];
auto &foo = *reinterpret_cast(buffer); // ← Is this UB?
foo.length = length;
do_something(&foo); // ← Is this UB?
std::println("Result: {}", foo.array[3]); // ← Is this UB?
}
Подробнее здесь: https://stackoverflow.com/questions/797 ... xible-arra
Мобильная версия