- 001
- 002
- 003
- 004
- 005
- 006
- 007
- 008
- 009
- 010
- 011
- 012
- 013
- 014
- 015
- 016
- 017
- 018
- 019
- 020
- 021
- 022
- 023
- 024
- 025
- 026
- 027
- 028
- 029
- 030
- 031
- 032
- 033
- 034
- 035
- 036
- 037
- 038
- 039
- 040
- 041
- 042
- 043
- 044
- 045
- 046
- 047
- 048
- 049
- 050
- 051
- 052
- 053
- 054
- 055
- 056
- 057
- 058
- 059
- 060
- 061
- 062
- 063
- 064
- 065
- 066
- 067
- 068
- 069
- 070
- 071
- 072
- 073
- 074
- 075
- 076
- 077
- 078
- 079
- 080
- 081
- 082
- 083
- 084
- 085
- 086
- 087
- 088
- 089
- 090
- 091
- 092
- 093
- 094
- 095
- 096
- 097
- 098
- 099
- 100
#include <stdio.h>
#include <stdlib.h>
/*
Declare array of functions that return array of functions with
one parameter - function accepting array of functions returning
a pointer to function void(void). No typedefs.
Decoded to the following:
1) An array of E.
2) E = a function that takes void and returns an array of D (returns an array taken to mean a pointer to D).
3) D = a function that takes C and returns void.
4) C = a function that takes an array of B and returns void.
5) B = a function that takes void and returns A.
6) A = a pointer to void(void).
*/
/* Using typedefs */
typedef void (*tA) (void);
typedef tA (*tB) (void);
typedef void (*tC) (tB b[]);
typedef void (*tD) (tC c);
typedef tD* (*tE) (void);
tE tArray[2];
/* Not using typedefs */
void (*_A) (void);
void (* (*_B) (void) ) (void);
void (*_C) ( void (* (*_B[]) (void) ) (void) );
void (*_D) ( void (*_C) ( void (* (*_B[]) (void) ) (void) ) );
void (** (*_E) (void) ) ( void (*_C) ( void (* (*_B[]) (void) ) (void) ) );
void (** (*_Array[2]) (void) ) ( void (*_C) ( void (* (*_B[]) (void) ) (void) ) );
/* Some concrete functions for testing */
void fA(void)
{
printf("fA\n");
}
tA fB(void)
{
printf("fB\n");
return &fA;
}
void fC(tB b[])
{
tA _a;
printf("fC\n");
_a = (*b[0])();
(*_a)();
}
void fD(tC c)
{
tB b[1];
printf("fD\n");
b[0] = &fB;
(*c)(b);
}
tD* fE(void)
{
tD *d;
printf("fE\n");
d = malloc(sizeof(tD));
d[0] = &fD;
return d;
}
int main()
{
tA _a;
tB _b;
tC _c;
tD _d;
tE _e;
tB b[1];
tD *d;
_a = &fA;
_A = &fA;
printf("_a\n");
(*_a)();
printf("_A\n");
(*_A)();
_b = &fB;
_B = &fB;
printf("_b\n");
_a = (*_b)();
(*_a)();
printf("_B\n");
_a = (*_B)();
(*_a)();
_c = &fC;
_C = &fC;
b[0] = _b;