3 ms·
Not necessarily. A string in C is usually a char. If you have a struct with a char and you copy it, you copy the pointer to the backing memory. This is analogou
by adastra22 2y ago
Not necessarily. A string in C is usually a char. If you have a struct with a char and you copy it, you copy the pointer to the backing memory. This is analogous to Go which also has a String be a pointer to the heap, but the behavior is different.
Go’s String is a char* that behaves like a char[] when copied.
- kstenerud 2y ago> Go’s String is a char* that behaves like a char[] when copied. Uhh, no. A go string is (effectively) a pointer to an immutable string of characters. When you do a = b, both a and b point to the same string (i.e. each is its own string struct, containing a pointer to the exact same array of character data). But if you try to get a byte[] from it, THEN it makes a copy.
- mauvia 2y agoI think the two *s merged into an italic there
- ajb 2y agoIs there a typo in this? C strings are not usually structs at all. Structs also do not behave differently if they contain a char.