3 ms·
same goes for more complicate type signatures like pointers to functions: void (*func)(int, int) = f1; where f1 is void f1(int a, int b); Another aspect
by ithkuil 15y ago
same goes for more complicate type signatures like pointers to functions:
void (*func)(int, int) = f1;
where f1 is
void f1(int a, int b);
Another aspect that might be confusing, but which becomes apparent once you see it through this light, is typedefs.
At the beginning it might seem that typedefs alias some A to some B.
typedef int myint; // OK
typedef myint int; // WRONG
Which could lead to confusing which side is the one you are defining and which is the produced.
But typedefs basically work as variable decl but they declare a type, so:
typedef void (*myfunc)(int, int);
this will declare myfunc as a type which is a pointer to a function expecting two integers and returning void.
- deleted 15y ago[deleted]
- gsg 15y agoI've always found it unsurprising that people find typedefs confusing. They're a storage specifier, which allows for some questionable constructs: int typedef x; typedef what; struct { int x; } typedef *x, y; enum { x } typedef; Storage specifiers are pretty weird. This nonsense is allowed at function or parameter list scope, but not file scope: void f() { enum { x } register; } void f(enum { x } register); I've never understood why Ritchie designed C's declaration syntax to have so many dumb edge cases.