News for hackers. Stuff that matters.
Re:Fat pointers in C using libcello by kortex on Wednesday April 29, 2020 @09:57AM (#23019241)
This is how Go does slices, though they are 3 fields:

    type slice struct {
        zerothElement *type
        len int
        cap int
    }
Though I suspect under the hood the len and cap are ordered first.

If it's good enough for C greybeard Ken Thompson and unix hacker Rob Pike, its good enough for me.

In fact I've looked for a port of go-style slices to C and haven't found one. Maybe people think sds is good enough?

Re:Fat pointers in C using libcello by LukeShu on Wednesday April 29, 2020 @10:19AM (#23019541)
> Though I suspect under the hood the len and cap are ordered first.

A slice is stored in memory as a `reflect.SliceHeader` https://golang.org/pkg/reflect/#SliceHeader ; the pointer does come first.

Re:Fat pointers in C using libcello by jgbaldwinbrown on Wednesday April 29, 2020 @01:18PM (#23021678)
I actually wrote a (sort of) Go-style slice library. It's a little heavier than Go slices because it allows for dynamic array resizing and tracking the parentage of slices:

https://github.com/jgbaldwinbrown/slice

It's just a proof-of-concept, though, and would need a lot of work to be used in anything serious.

Re:Fat pointers in C using libcello by int_19h on Wednesday April 29, 2020 @06:50PM (#23025489)
Go has a rather idiosyncratic take on arrays and how they're used, which is reflected in its slices. I can't think of any other language or framework that did it this way.
Re:Fat pointers in C using libcello by saati on Thursday April 30, 2020 @02:38AM (#23028054)
Rust Vec has the same representation.