Comment

Comment by xscott

The biggest problem with C's pointer syntax is that it's prefix. If pointers were suffix, perhaps using a character that isn't doing primary duty as the multiplication operator, there wouldn't be any need for a Gibberish to English translator. Maybe think of @ as "address":

    int i;          // variable which is integer
    int p@;         // pointer that returns integer
    int f();        // function returns integer
    int f@();       // pointer to function
    int f()@;       // funtion that returns pointer
    int a[10];      // array of ten integers
    int a[10]@;     // array of ten pointers
    int a@[10];     // pointer to and array
    int a[10]()@;   // array of ten functions that return a pointer
Of course C is stuck with accidents/decisions made 50 years ago. But a language like Go turns all the declaration syntax on its head and still doesn't solve the problem. Rob Pike's blog post says as much (scroll to the bottom section on pointers):

https://go.dev/blog/declaration-syntax

He suggests Pascal's caret syntax (^), which wouldn't work if it was also used as the binary xor operator.

parent xscott 4 years ago

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton