Reputation: 65004
Let's say I have the following in my code:
err := "This is a very long error message"+
"that spans multiple lines."
Will Go compile this under the hood into one string, or is there some small penalty associated with doing the addition there?
Upvotes: 3
Views: 931
Reputation: 28375
It's a constant expression and is specified to be evaluated at compile time.
Upvotes: 8
Reputation: 166765
It's compiled as one string for Go 1.3.
go.string."This is a very long error messagethat spans multiple lines."
It's probably one string for earlier versions too.
Upvotes: 2