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
Closed

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

fabulousduck opened this issue Nov 12, 2018 · 3 comments
Labels
Documentation FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@fabulousduck
Copy link

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
Copy link

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
Copy link

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 the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Nov 12, 2018
@ianlancetaylor ianlancetaylor added this to the Go1.12 milestone Nov 12, 2018
@gopherbot
Copy link

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

@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.
Labels
Documentation FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

5 participants