Không khai báo struct
nào theo tiêu chuẩn C. 6.7.2.1 (8) trong n1570:
If the struct-declaration-list does not contain any named members, either directly or via an anonymous structure or anonymous union, the behavior is undefined.
Và đoạn 18 trong cùng một phần:
As a special case, the last element of a structure with more than one named member may have an incomplete array type; this is called a flexible array member. 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.
(tôi nhấn mạnh)
thành viên mảng linh hoạt không được phép trong C++, vì vậy mã không phải là C++ hợp lệ.
Vì nó không phải là mã hợp lệ, các giá trị được báo cáo bởi sizeof
cho những điều này là vô nghĩa.
Nguồn
2012-06-10 19:38:04
Thật kỳ quặc, 'sizeof' không bao giờ có thể là _0 _... –
@ K-ballo: Đối với các mảng linh hoạt như' char x [] 'sizeof là 0. – Tudor
@Tudor: mảng linh hoạt, có phải là phần mở rộng của trình biên dịch không? –