Given
struct Foo {
uint32_t a;
uint32_t b[];
};
What is sizeof(Foo)
? Is it implementation-defined or undefined behaviour? Does the answer differ for C vs C++?
Given
struct Foo {
uint32_t a;
uint32_t b[];
};
What is sizeof(Foo)
? Is it implementation-defined or undefined behaviour? Does the answer differ for C vs C++?
The compiler will ignore the flexible array member as it were not there.
C11-§6.7.2.1 (p18)
[...] In most situations, the flexible array member is ignored. In particular, the size of the structure is as if the flexible array member were omitted except that it may have more trailing padding than the omission would imply [...].
AFAIK, flexible array member is not the part of C++ standard till c++14. But, GNU support it as an extension. Behaviour will be similar for both C and C++.
struct { char a; double d[]; };
. If you ignored d
, the size could be 1. –
Earpiece © 2022 - 2024 — McMap. All rights reserved.
printf
– Cellaprintf
won't tell you that. – Breena