Kevin Burke
Kevin Burke

Reputation: 65004

Does the Go compiler concatenate strings separated by a plus sign?

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

Answers (2)

Sonia
Sonia

Reputation: 28375

It's a constant expression and is specified to be evaluated at compile time.

Upvotes: 8

peterSO
peterSO

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

Related Questions