News for hackers. Stuff that matters.
Re:Go Slices Are Fat Pointers by WalterBright on Sunday June 30, 2019 @07:25PM (#20321243)
D slices are fat pointers as well:

https://dlang.org/spec/arrays.html#dynamic-arrays

My suggestion for C to adopt fat pointers:

https://www.digitalmars.com/articles/b44.html

Re:Go Slices Are Fat Pointers by masklinn on Monday July 01, 2019 @02:38AM (#20322959)
> D slices are fat pointers as well:

So are Rust's.

Possibly more interestingly, so are its trait objects, the trait object pointer is a (vtable, instance) rather than (instance*, length).

Also of note: that applies to "owned pointers" (`Box`) not just "references", despite the former looking very struct-like: https://play.rust-lang.org/?version=stable&mode=debug&editio...

In a way, C++ and Rust (and possibly D?) have pretty much an infinity of fat pointers as anything can be made to deref' to something else, and be more than one pointer wide (e.g. C++'s std::string and std::vector and Rust's String and Vec)

Re:Go Slices Are Fat Pointers by ainar-g on Monday July 01, 2019 @03:17AM (#20323134)

  > Possibly more interestingly, so are its trait objects, the trait object pointer is a (vtable,
  > instance) rather than (instance*, length).
The Go interfaces are the same. See https://research.swtch.com/interfaces.
Re:Go Slices Are Fat Pointers by mhh__ on Monday July 01, 2019 @12:09AM (#20322397)
A chaotic part of me thinks that C should be illegal for security code for the lack of this.
Re:Go Slices Are Fat Pointers by aitchnyu on Monday July 01, 2019 @05:41AM (#20323785)
Just Googled and seems fat pointers can at least prevent buffer overflow. I want to know more about other returns and costs on changing C to fat pointers.

https://security.stackexchange.com/questions/155572/how-are-...

Re:Go Slices Are Fat Pointers by simias on Monday July 01, 2019 @07:59AM (#20324445)
They can prevent some buffer overflows, assuming that the data in the fat pointer remains correct. If you want to prevent buffer overflows completely you need to go well beyond that and effectively either use a higher-level language with a runtime and GC making sure everything remains coherent or do what Rust is doing with its borrow checker.

Not that I'm against fat pointers in C, I always thought that in hindsight not having a primitive "slice" type was a mistake. In particular using NUL-terminated strings instead of slices is both error-prone and makes implementing even basic string-splitting functions like strtok annoying or inefficient (you need to be able to mutate the source string to insert the NULs or you have to allocate memory and copy each component. If you had slices you could easily return a portion of the string without mutation or copy).

Re:Go Slices Are Fat Pointers by codedokode on Tuesday July 02, 2019 @09:06AM (#20334587)
> If you had slices you could easily return a portion of the string without mutation or copy).

In this case you get another problem: how to free memory when there might be many slices pointing at it.

Re:Go Slices Are Fat Pointers by ummonk on Monday July 01, 2019 @02:54AM (#20323031)
I mean, some types of implementation of fat pointers are fully compatible with the C spec, and would mean that undefined behavior will result in a crash rather than overflow. Slice behavior would not exist though.
Re:Go Slices Are Fat Pointers by Crinus on Monday July 01, 2019 @06:22AM (#20323983)
How does

    extern void foo(char a[..]);
differ from

    extern void foo(size_t dim, char a[dim]);
if they are meant to be binary compatible?
Re:Go Slices Are Fat Pointers by pjmlp on Monday July 01, 2019 @10:06AM (#20325336)
The programmer doesn't have to keep both in sync manually, so there is less chance that they blow up, as it happens regularly in C code, even after being reviewed.
Re:Go Slices Are Fat Pointers by inlined on Monday July 01, 2019 @10:33AM (#20325610)
I don’t recall that syntax being valid C. I thought the length modifier had to be a literal.
Re:Go Slices Are Fat Pointers by pjmlp on Monday July 01, 2019 @10:37AM (#20325653)
It doesn't matter, because it gets ignored anyway.
Re:Go Slices Are Fat Pointers by skrebbel on Monday July 01, 2019 @02:34AM (#20322939)
Did people in the C community consider your proposal?
Re:Go Slices Are Fat Pointers by WalterBright on Monday July 01, 2019 @03:28AM (#20323184)
I haven't officially proposed it, but every time I've shown it to C people they're just silent - no response.

But anyway, you can use D in BetterC mode and have bounds checked slices!

https://dlang.org/spec/betterc.html

Re:Go Slices Are Fat Pointers by kryptiskt on Monday July 01, 2019 @04:39AM (#20323515)
You might be interested in this paper: "CheriABI: enforcing valid pointer provenance and minimizing pointer privilege in the POSIX C run-time environment" https://blog.acolyer.org/2019/05/28/cheri-abi/
Re:Go Slices Are Fat Pointers by x0re4x on Monday July 01, 2019 @05:31AM (#20323736)
I would interpret the silence of C people as "Thanks, but no, thanks." The success of C for such long time without having fat pointers, exceptions, RAII, etc... is probably an indication they weren't needed that much.

(Jonathan Blow: Ideas about a new programming language for games.) https://www.youtube.com/watch?v=TH9VCN6UkyQ&list=PLmV5I2fxai...

Re:Go Slices Are Fat Pointers by pjmlp on Monday July 01, 2019 @10:08AM (#20325357)
C´s success is just like PHP and JavaScript successes.

When a language owns the platform its quality comes second.

Re:Go Slices Are Fat Pointers by inlined on Monday July 01, 2019 @10:34AM (#20325623)
Languages are maintained by people. When people have a monopoly quality comes second.
Re:Go Slices Are Fat Pointers by pjmlp on Monday July 01, 2019 @10:36AM (#20325646)
Whose interests are to push certain platforms.