Given:
typedef type-declaration synonym;
I can see how:
typedef long unsigned int size_t;
declares size_t
as a synonym for long unsigned int
, however I (know it does but) can't see exactly how:
typedef int (*F)(size_t, size_t);
declares F
as a synonym for pointer to function (size_t, size_t) returning int
typedef's two operands (type-declaration, synonym)
in the first example are long unsigned int
and size_t
.
What are the two arguments to typedef in the declaration of F
or are there perhaps overloaded versions of typedef?
If there is a relevant distinction between C and C++ please elaborate otherwise I'm primarily interested in C++ if that helps.
Type declarations using typedef
are the same as corresponding variable declarations, just with typedef
prepended. So,
int x; // declares a variable named 'x' of type 'int'
typedef int x; // declares a type named 'x' that is 'int'
It's exactly the same with function pointer types:
int(*F)(size_t); // declares a variable named F of type 'int(*)(size_t)'
typedef int(*F)(size_t); // declares a type named 'F' that is 'int(*)(size_t)'
It's not a "special case;" that's just what a function pointer type looks like.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With