-
Notifications
You must be signed in to change notification settings - Fork 17.9k
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
fmt: Sscanf %c skips a blank in Go1.5; not in Go1.3.3, nor in C #12275
Comments
/CC @robpike |
1.4 also gets a space. Arguably, it's doing what the docs say, but this new behavior, a consequence of a major internal restructuring, is clearly a change in behavior. Should perhaps be fixed. I wish instead we could just tell everyone not to use fmt.Scan*. I wish they had never been written. |
CL https://golang.org/cl/13821 mentions this issue. |
CL https://golang.org/cl/14395 mentions this issue. |
…kip spaces at %c In short, %c should just give you the next rune, period. Apparently this is the design. I use the term loosely. Fixes #12275 Change-Id: I6f30bed442c0e88eac2244d465c7d151b29cf393 Reviewed-on: https://go-review.googlesource.com/13821 Reviewed-by: Andrew Gerrand <adg@golang.org> Reviewed-on: https://go-review.googlesource.com/14395
What version of Go are you using (go version)?
I found this when upgrading from Go 1.3.3 to Go 1.5
What operating system and processor architecture are you using?
What did you do?
$ cat scango.go
What did you expect to see?
I expected what Go 1.3.3 did: it always gets the first character in the scanned string, either "A" or " ":
$ go run scango.go
n= 1 x= 65 err= (0x0,0x0)
n= 1 x= 32 err= (0x0,0x0)
n= 1 x= 32 err= (0x0,0x0)
That's also what my C compiler does
/* gcc version 4.8.4 (Ubuntu 4.8.4-2ubuntu1~14.04) */
$ cat scanc.c
$ gcc scanc.c
$ ./a.out
n=1 <65>
n=1 <32>
n=1 <32>
What did you see instead?
Under Go 1.5, it skips the blank, and advances to the "A" (in the second clause) or EOF (in the third clause):
$ go run scango.go
n= 1 x= 65 err= (0x0,0x0)
n= 1 x= 65 err= (0x0,0x0)
n= 0 x= 65 err= (0x7f555757b028,0xc82000a1d0)
The text was updated successfully, but these errors were encountered: