On Monday, 1 February 2021 at 16:19:13 UTC, Ruby The Roobster wrote:
Thanks. However for a char[], .sizeof = .length because a char is one byte.

Nope, char[].sizeof is a platform-specific constant not related to the length at all.

void main() {
        import std.stdio;
        char[] a = "test".dup;
writeln(a.sizeof); // 8 on 32 bit, 16 on 64 bit independent of content
        writeln(a.length); // 4 because of the content "test"
}


With a static array sizeof and length would happen to match but a dynamic array is different. sizeof is the size of the length and pointer, not the content.

Reply via email to