My brilliant idea for "any VLA type" was thwarted because of the stupid rules for array declarators in parameters goddamn I hate that language rule soooooooo much.

"Jesse what the fuck are you talking about"

void purr(int n, int arr[]);
void purr(int n, int arr[*]);
void purr(int n, int arr[static 1]);
void purr(int n, int arr[n]);
void purr(int n, int arr[static n]);
void purr(int n, int arr[1]);
void purr(int n, int* arr);

These are all identical, compatible declarations. That means all of these are just a fancy way of passing a pointer to a function, modulo your compiler implementer giving an iota of a damn and doing some type checking for you.

That means if you wanted to use ANY of the above syntaxes for anything else, the minute you tried to use it for a parameter it would once again become a pointer. Not just at the API level because of C's rules, but the ABI level.

It means you have to choose a sufficiently fucked up notation if you wanted to get built-in language spans or a built-in "any VLA" type, forcing C to choose weirder things just to have syntax for something actually useful and not just a shitty compiler hint.

@thephd void aaaa(struct { int arr[n]; }) maybe?
@thephd (we do genuinely wish we had anonymous structs tho)
@thephd Reminds me of wrapping a C library with C++, where when the C library expected an array of size 3, I opted to accept an std::array of size 3 (span wasn't available in this project). I quickly found out that the `.data()` of the array returning a T* and the statically sized C array weren't compatible without a very ugly cast.

@thephd Oof, heaven forbid C actually makes progress as a language - let's just add another notation!

I suggest:
void purr(int n, __this_is_a_sodding_array int arr[n]);

@thephd obviously the solution is to find novel crap to put inside the square brackets.

@lenary @thephd E.g.

int array[register n]
int array[volatile n]
int array[ [n] ] // spaces are necessary
int array[ struct n ]
int array[ for n ]

@foonathan @lenary So these seem silly, but hear me out tor a built-in Span type ...

int span[auto] = some_array;

Yeah? Yeeeah? :D

@thephd @lenary It could also mean the size is deduced...

What about `int span[...] = some_array`?

@foonathan @lenary That's the Walter Bright / D syntax (except it's 2 dots rather than 3). I'd imagine if we used 3, C++ would lose their minds due to conflating the variadic expansion bit with this...
@thephd @foonathan @lenary There's
also the Walter White syntax:
int span[💎] = ...;

@thephd @lenary Alternatively, put a type name in there:

int span[size_t] = ...;

The type is then used as the size type for the span.

@thephd void purr(int i, int n, int arr[i,i+n]);
purr(int n, int arr[0,n]); 🫠

@thephd Getting the urge to write some macros.

*Shudder*

_Generic macros.

@thephd Yeah, sorry for pointing out that problem. But what is so terribly about introducing a new symbol [?], [:], [@] etc? While reusing existing syntax would have been better, I do not think why this would be "fucked up". WG21 does it five times before breakfast on a bad day. I mean you also had no doubts about C++'s contract syntax that will force us to have crap such as _Pre and _Post. This is what I would call fucked up.

@uecker It's just that all of the syntaxes that fit "neatly" into the space there and that work with user intuition are basically taken as a form of (mostly worthless) annotation. So it feels like a tremendous waste of syntax space, and it's syntax space we won't ever be able to get back without an aggressive deprecation campaign.

We're losing an awful lot of good things to array decay semantics in the language and it just feels kind of bad. 😭

@thephd Stephan has infected you with the `purr` disease I see
@thephd i would totally buy a book if you wrote about "stupid rules of PL" or something like that

@thephd

Man-ray: "Arrays are declared with square brackets, right?"
Patrick: "Yup"
M: "And this parameter is declared with square brackets"
P: "Right"
M: "So this parameter is declared like an array"
P: "Makes sense to me"
M: "So treat it as an array"
P: "That's a pointer"

Unrelated: I was Today Years Old when I realized that Pam (the only visible person depicted in the above meme) is pulling a prank on the unseen person she is presenting them to.

Up till this point, I always thought the meme was that Pam thought they were they same picture when they clearly weren't.

🧠 💥

@drmorr @sjolsen @thephd -fno-strict-aliasing says hi, and also several ruder things I don't want to repeat

@sjolsen
Well an array is kinda like a pointer isn't it ;)

@thephd

@sjolsen @thephd a pointer to an array or an array of pointers?

@thephd
totally minor by comparison but it currently also treads on

void f (size_t N, void bytes[N]);

because right before it throws away the array type, it... still requires it to be an array type 😓

which just feels petty

@thephd who is the ruler of the rules though, hm? Would it be perhaps you who proposes language features?
@thephd if you're being brilliant and the language is stopping you, clearly just change the language to allow you and everyone else to thrive
@gaycodegal Alas, backwards compatibility 😔

@thephd

@gaycodegal

C99 already had the option to make

void f(int[6]);

mean something distinct from

void f(int *);
void f(int[60]);

and decided that the backwards compatibility case for people writing in a constant number but not really meaning it, was more compelling than turning obviously-wrong declarations into errors

instead you need a new keyword (that is widely misunderstood and hated) if you want it to even be eligible for a warning

(in WG14's defence we more or less agreed "morally" to fix this per a proposal by @uecker but didn't get to it in the C23 cycle)

@erisceleste @gaycodegal @uecker Good ol' ancestors not saving us by choosing compat over boldness. Same situation where everyone complained to me about nullptr in C. But, when we had proposals before to mandate #define NULL (void*)0, to prevent the issues that obviously came up with ... functions and similar conceptual problems with not-exactly-constant-zero being used to initialize a pointer, they all got weak in the knees and rejected it.

So now, you have to do the "well, we have to simplify the situation by adding something new". And then people get all pissy when if they had ever put in the work to make 0 a less attractive option for the null pointer, or done even a deprecation 20 years ago we'd have a leg to stand on and a reason to fight for something today.

But they didn't.

So we don't.

@erisceleste @gaycodegal @uecker Call K&R whatever you want, but they were so on-the-ball with understanding that people in the future deserved better. They nuked-from-orbit the literal function declaration and definition syntax that had their name on it — from the very first standard version of C — by putting it in deprecated.

They understood it was better to look to the future rather than endlessly cling to what had been.

I wish people who worked with C today were even a smidgen as brave as those two.

@thephd @erisceleste @gaycodegal @uecker posts like this makes me wonder how feasible it would be to like. fork C. and turn it into a new C-like language unencumbered by historical artifacts

and before anyone brings up C++: no not like that

@eniko

so C is often called "mistakenly called simple", but there is a simple language in there struggling to get out of the 600-page spec

the hard part is a) getting agreement on the useful parts; and b) getting people to adopt your subset; and then c) gaining enough traction with your subset that anyone will touch new features

(like if it was up to me id take a flamethrower to floating point in its entirety and put it in an entire separate document, with the core language only saying "there is a tower of reals that have distinct types" such that you can define that float is separate from int but not otherwise how, beyond size/alignment/promote-rank

everybody is probably glad this sort of thing isn't up to me 😅)

if you make your subset minimal enough and associate it with a use case - say cough a specific virtual console or machine? - you might find adoption is a lot easier

but anyway C99 is the story of how evolution attempts can falter

@eniko
also if you try to fix things like pointers - which are simple and complex at the same time, but the simplicity isn't all good - you can very easily get to the point where it's not worth marketing the language as C* any more

(id love a small language that restricts pointer/ref usage even beyond what Rust does, but ... not sure how wide the demographic for it actually is)

@erisceleste @eniko I'd put 90% of Fortran's math functions into a standard library, revise string handling and move it to a library, add enums, contracts, and type constraints (and maybe posits https://en.m.wikipedia.org/wiki/Unum_(number_format) ), and devote 2-3 standard libraries just to physical and numerical constants, all date-stamped and validated. Overhaul the OO syntax if not the whole model. Take a flamethrower to any remaining undefined behavior. Something low-magic with speed and simplicity and first-class features that focus on correctness, accuracy, and safety. 1-indexing stays.
Unum (number format) - Wikipedia

@erisceleste @eniko The actual language (excluding library) is about 180 pages.

And I like to point out that there is no agreement what it evens means to "fix" C. I think that some of the stuff we added in C23 (in the name of "fixing C") makes it worse and adds a substantial amount of complexity. I could point to many new GCC bugs or substantial additional complexity in the implementation.

I also like C very much how it is - more than C++ or Rust. I think compilers need to improve though.

@erisceleste @eniko What would make the world a better place if we had a rule that anybody who wants to add a feature to C has to fix one bug in GCC per sentence added to the standard.

@eniko @thephd @erisceleste @gaycodegal @uecker plenty of people have forked C, that's called being a C vendor /s

forking C is probably extremely feasible, but it wouldn't solve the problem of C, The Abominable Beast That Permeates Our Computers, being A Complete And Utter Mess. which is why i have such mad respect for JeanHeyd and others' valiant fights to clean that shit up

@eniko @thephd @erisceleste @gaycodegal @uecker It occurs to me (a C programmer) that sometimes the way one goes about this is to remove the historical artifacts from source code and replace them with the actual improvements that modern readers will understand
@eniko @thephd @erisceleste @gaycodegal @uecker this has been probably been considered already by people more knowledgeable than me or whatever, but how about rather than forking C, putting a pre-processor on it? Not like early C++ adding new features, just taking a semantically nice subset of C and making it syntactically nice to use? So you could add some ugly syntax to C that does what ThePHD wants, and then give a nice syntax to it in this hypothetical C frontend.

@lonjil

@JensGustedt has one at Shnell https://gustedt.gitlabpages.inria.fr/shnell/

there's no upper limit to what languages you can just compile to C if you like though, and of course there's a ton of variations on PreScheme and parentheC for instance that use Lisp notation to describe C semantics directly (so you can use much more powerful Lisp macros)

Objective C started as such a beast, too

shnell – source-to-source compiler enhancement

@erisceleste Soon, there will also be lip, the language independent preprocessor, with a C and C++ compatible specification, bindings for other languages including md, an open source implementation and plenty of new features, such as `#expand` and `#bind`, programmable recursion
@erisceleste In fact it is now called eĿlipsis, is released, and implements all these nice features https://gustedt.gitlabpages.inria.fr/ellipsis
eĿlipsis: eĿlipsis, a language independent preprocessor