Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

spec: documentation of len() in string type unclear #28736

Closed
fabulousduck opened this issue Nov 12, 2018 · 3 comments

Comments

@fabulousduck
Copy link

@fabulousduck fabulousduck commented Nov 12, 2018

The length of a string <code>s</code> (its size in bytes) can be discovered using

The documentation on how specifically len() can be used to determine the size of a string type in bytes can be confusing as this would make you expect that len("go") would return 16 (like unsafe.Sizeof("go") would) but actually gives you 2

I would like to ask for a better phrasing of how to use len() on string type in the docs

@go101

This comment has been minimized.

Copy link

@go101 go101 commented Nov 12, 2018

"go" has two bytes, so len("go") is 2. The docs is very clear on this. Why confused?

unsafe.Sizeof(anyStr) always returns 16, for every string value occupies 16 bytes in memroy on 64-bit arch.

@go101

This comment has been minimized.

Copy link

@go101 go101 commented Nov 12, 2018

Ah, some misunderstanding here.
The doc is really not very clear here.
(the number of bytes stored in the string) would be better.

@ianlancetaylor ianlancetaylor changed the title documentation of len() in string type unclear spec: documentation of len() in string type unclear Nov 12, 2018
@ianlancetaylor ianlancetaylor added this to the Go1.12 milestone Nov 12, 2018
@gopherbot

This comment has been minimized.

Copy link

@gopherbot gopherbot commented Nov 12, 2018

Change https://golang.org/cl/149077 mentions this issue: spec: be clearer about definition of string length

@gopherbot gopherbot closed this in de578dc Nov 13, 2018
@golang golang locked and limited conversation to collaborators Nov 13, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
5 participants
You can’t perform that action at this time.