News for hackers. Stuff that matters.
Re:C Gibberish to English by pavlov on Thursday November 14, 2024 @06:30AM (#42135194)
Use typedef?

Granted, the function pointer syntax is forever confusing (to me anyway). The rest is easily tackled by naming things.

Even for function pointers, it’s just one lookup and then you can copy-paste the typedef for any other function pointer types in the project.

Re:C Gibberish to English by dapperdrake on Thursday November 14, 2024 @07:19AM (#42135508)
Reading C Type Declarations: http://unixwiz.net/techtips/reading-cdecl.html

(NOT the author. It simply helped me.)

Re:C Gibberish to English by sebstefan on Thursday November 14, 2024 @06:55AM (#42135347)
>Use typedef?

What if you're given somebody else's code and you need to understand it to put a typedef there

Re:C Gibberish to English by DaiPlusPlus on Thursday November 14, 2024 @07:31AM (#42135589)
Welp, if it’s that bad then shrug and use a #define

(Yes, this is a joke)

Re:C Gibberish to English by jacoblambda on Thursday November 14, 2024 @11:47AM (#42138050)
The trick is to just assert equal types. Most compilers have extensions that allow you to easily compare type equality (and C23 actually standardizes the `typeof()` operator).

So you basically take your ugly type, put it in a #define and then create a static assertion that matches the type against said ugly type.

Now the compiler will throw a shit fit if the types don't match. Have fun breaking the type up into smaller pieces until you have something legible.

Re:C Gibberish to English by khrbtxyz on Thursday November 14, 2024 @10:18AM (#42136997)
Function typedefs make this less confusing by removing awkward parentheses. e.g.

  typedef int read_block_fn(void *context, u8 *buf, unsigned int block, size_t len);
https://github.com/torvalds/linux/blob/0a9b9d17f3a781dea03ba...