top | item 41663873

(no title)

wolfspaw | 1 year ago

Really liked the trick of defining the struct in the return part of the function.

Array pointers: Array to pointer decay is extremely annoying, if it was implemented as Array to "slice" decay it would be great.

Static array indices in function parameter declarations: awesome, a shame that C++ (and Tiny C) do not support it >/

flexible array member: extremely useful, and now there are good compiler flags for ensuring correct flexible array member usage

X-Macro: nice, no-overhead enum to string name. Didn't know the trick

Combining default, named and positional arguments: Named-arguments/default-arg, C version xD. It would be cool if it was added to C language as a native feature, instead of having to do the struct hiding macro.

Comma operator: really useful, specially in macros

Digraphs, trigraphs and alternative tokens: di/tri/graphs rarely useful, alternatives synonims of iso646.h are awesome, love using and/or instead of &&/||

Designated initializer: super awesome, could not use if you wanted C++ portability. Now C++ supports some part of it.

Compound literals: fantastic, but in C++ it will explode due to stack deallocation in the same line. C++ should fix this and allow the C idiom >/

Bit fields: nice for more control of structs layout

constant string concat: "MultiLine" String, C version xD

Ad hoc struct declaration in the return type of a function: didn't know this trick, "multi value" return, C version xD

Cosmopolitan-libc: incredible project. Already knew of it, its awesome to offer a binary that runs in all S.Os at the same time.

Evaluate sizeof at compile time by causing duplicate case error: ha, nice trick for debugging the size of anything.

discuss

order

WalterBright|1 year ago

> Array to pointer decay is extremely annoying, if it was implemented as Array to "slice" decay it would be great.

It's not just annoying, it's the major source of bugs in shipped code. A fix:

https://www.digitalmars.com/articles/C-biggest-mistake.html

wolfspaw|1 year ago

I agree wholeheartedly, I really liked your article and fix.

(In fact, I already had your article bookmarked xD, and I’m familiar with and truly admire your work)

fuhsnn|1 year ago

>Static array indices in function parameter declarations: awesome, a shame that C++ (and Tiny C) do not support it >/

The first array size is actually always decayed to a pointer, supporting it in a compiler without analysis passes like TCC is just a matter of skipping the "static" token and the size.

jcelerier|1 year ago

> Static array indices in function parameter declarations: awesome, a shame that C++ (and Tiny C) do not support it >/

C++ does?

    void print(const int (&array)[5]) {
      for(size_t i = 0; i < size; ++i)
        std::cout << array[i] << " ";
    }
will fail at compile time if you pass it anything other than an int[5] array

mananaysiempre|1 year ago

Including an int[6] array, unlike with int[static 5]. This is usually not what you want.

xeyownt|1 year ago

Pointer decay is not a mistake.

It is what allows to do int * p = arr, and looping on array element with p++.

Keeping array type you would jump beyond the last element at first iteration.

kaba0|1 year ago

It is, an array and a pointer are different types. There could be ways to convert it to a pointer, but it shouldn’t happen at so many places, implicitly.