The field can't be reordered.
I want to use zero-sized data type to mark offset and has no effect on 
struct size, I can take the address of it and use it like:
```go
c := ...
cmd := (*[SIZE]byte)(unsafe.Pointer(&c.Inner))
```
I am using this on mmap-ed memory.
I've found a workaround to do the same thing by adding `c` pointer with 
it's data size

Pada Jumat, 14 Oktober 2022 pukul 00.21.38 UTC+7 Marcel Huijkman menulis:

> What is the usage of that zero-sized data type? Can you give an example 
> where that Inner field has any usage?
>
> On Wednesday, October 12, 2022 at 7:27:14 PM UTC+2 
> axel.wa...@googlemail.com wrote:
>
>> You can re-order the fields to get the desired effect:
>> https://go.dev/play/p/E1KTqVp0i-v
>>
>> On Wed, Oct 12, 2022 at 6:01 PM Richiise Nugraha <rich...@gmail.com> 
>> wrote:
>>
>>> Hi, I am looking for zero-sized data type, something like Flexible Array 
>>> Member.
>>> The size of `struct {}` is indeed zero, but for what reason when it's 
>>> inside a struct with another member say (
>>> https://go.dev/play/p/DpydJIke7dS):
>>>
>>> type C struct {
>>>     Pre   uint64
>>>     Inner struct{}
>>> }
>>>
>>> That struct sized for 16, while the sum of all member sizes is only 8, 
>>> it's like there's hidden padding/align.
>>>
>>> Thanks!
>>> Nugraha
>>>
>>> -- 
>>> 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.
>>> To view this discussion on the web visit 
>>> https://groups.google.com/d/msgid/golang-nuts/2f7254a8-379a-4dc2-bf10-70ee7a209af2n%40googlegroups.com
>>>  
>>> <https://groups.google.com/d/msgid/golang-nuts/2f7254a8-379a-4dc2-bf10-70ee7a209af2n%40googlegroups.com?utm_medium=email&utm_source=footer>
>>> .
>>>
>>

-- 
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/d76e1e0c-af1e-4741-b868-842cc1d587e3n%40googlegroups.com.

Reply via email to