On Sunday, February 25, 2018 at 11:46:02 PM UTC-5, Rob 'Commander' Pike 
wrote:
>
> No. As I said, there are no guarantees. As it says in 
> https://golang.org/doc/go1compat:
>
>
>    - Use of package unsafe. Packages that import unsafe 
>    <https://golang.org/pkg/unsafe/> may depend on internal properties of 
>    the Go implementation. We reserve the right to make changes to the 
>    implementation that may break such programs.
>
>
>
Will the 3 APIs and the unsafe.Pointer be always there?
Will the "sync/atomic" package get broken?
This atomic package imports unsafe.
 

>
>
> On Mon, Feb 26, 2018 at 1:15 PM, <di...@veryhaha.com <javascript:>> wrote:
>
>>
>>
>> On Sunday, February 25, 2018 at 7:38:22 PM UTC-5, Rob 'Commander' Pike 
>> wrote:
>>>
>>> The main rule about unsafe is that your program might work or might not. 
>>> There are no guarantees either way. That's why it's called 'unsafe' and why 
>>> you shouldn't use it. Your program that 'works' today could break tomorrow.
>>>
>>
>> ok, but, is there always an unsafe alternative/variant existing later?
>>  
>>
>>>
>>> -rob
>>>
>>>
>>> On Mon, Feb 26, 2018 at 4:43 AM, Marvin Renich <mr...@renich.org> wrote:
>>>
>>>> * di...@veryhaha.com <di...@veryhaha.com> [180225 11:37]:
>>>> > I think I get it.
>>>> > Because the above program tries to modify the constant (or program) 
>>>> zone,
>>>> > which is not allowed.
>>>> > The following program works:
>>>>
>>>> But, note that the language spec does not guarantee it to work.  The
>>>> compiler is free to recognize what that first line is doing and optimize
>>>> the assignment into a string in a R/O memory segment.  The optimization
>>>> is legal because the compiler does not have to recognize the use of
>>>> unsafe to determine the programmer's intent to subvert the type system.
>>>>
>>>> > package main
>>>> >
>>>> > import "fmt"
>>>> > import "unsafe"
>>>> > import "reflect"
>>>> >
>>>> > func main() {
>>>> >     s := string([]byte{'k', 'e', 'e', 'p'})
>>>> >     hdr := (*reflect.StringHeader)(unsafe.Pointer(&s))
>>>> >     byteSequence := (*byte)(unsafe.Pointer(hdr.Data))
>>>> >     fmt.Println(string(*byteSequence)) // k
>>>> >     *byteSequence = 'j' // crash here
>>>> >     fmt.Println(s) // expect: jeep
>>>> > }
>>>>
>>>> ...Marvin
>>>>
>>>> --
>>>> 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...@googlegroups.com.
>>>> For more options, visit https://groups.google.com/d/optout.
>>>>
>>>
>>> -- 
>> 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...@googlegroups.com <javascript:>.
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>

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