On Wed, Sep 5, 2018 at 4:00 PM Eric Raymond <e...@thyrsus.com> wrote:

> If I have multiple occurrences of a string constant in source code - say,
"M" - can I count on the compiler to create one static instance and pass
references to it everywhere?

It's unspecified, so strictly speaking you cannot. (Also, everything in Go
is passed by value). However, all well known Go compilers do put text
literals into the text segment and one can reasonably expect the linker to
coalesce them. The implementation of a string variable is a two worded
struct having a pointer to the string value and the length of the string
value. Only this struct is being passed around (by value), the actual value
the struct points to never is.

-- 

-j

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to