On Sun, Feb 28, 2021 at 7:52 AM tapi...@gmail.com <tapir....@gmail.com> wrote:
>
> On Sunday, February 28, 2021 at 8:29:51 AM UTC-5 Ian Lance Taylor wrote:
>>
>> On Sat, Feb 27, 2021 at 8:00 PM tapi...@gmail.com <tapi...@gmail.com> wrote:
>>
>> > 2.
>> >
>> > func String2ByteSlice(s string) []byte {
>> > return *(*[]byte)(unsafe.Pointer(&struct{string; int}{s, len(s)}))
>> > }
>>
>> This is more likely to work but it's not safe.
>
>
> Why? For slice field order is undefined?

Yes: the language does not define what a slice looks like in memory.
It may be implemented differently by different implementations,
including by different releases of the same implementation.

Ian

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CAOyqgcUvvZAK8oiaKa%2BnaCZqmF6xQr6b8nReXA%2By%3DO2xcr2Q1Q%40mail.gmail.com.

Reply via email to