I understand that a string is a 2 words data structure where one word holds the address of the underlying slice of bytes and the word holds the length.
Given a variable defined like this a := "a string literal"
, is there a way to view (or print) the content of the variable in its 2 words format?
CodePudding user response:
is there a way to view (or print) the content of the variable in its 2 words format?
No, because this is an unspecified implementation detail.
If you are okay with code that might brake: Use reflect.StringHeader. See unsafe.Pointer point (6) on how to do this.
Best not to do this. As said: this is a deliberately hidden implementation detail.