IMPORTANT If you decide to try the following codes, please do so at your own risk.
If the program is out of control and you are in trouble, press <Ctrl-C> to stop it.
An array of pointers to functions
# define __cdecl
# include <stdio.h>
# include <stdarg.h>
signed(__cdecl ff(signed(arg),signed char(**argp))) {
auto signed char *b;
if(!argp) return(0x00);
if(!(*argp)) return(0x00);
b = (*argp);
argp++;
printf("%s",b);
if(!arg) return(0x01);
return(0x01+(ff(arg,argp)));
}
signed(__cdecl f1(signed char *argp,...)) {
auto signed char **v;
if(!argp) return(0x00);
v = (&argp);
return(ff(0x01,v));
}
signed(__cdecl f0(signed char *argp,...)) {
auto signed char **v;
if(!argp) return(0x00);
v = (&argp);
return(ff(0x00,v));
}
signed(__cdecl main(void)) {
auto signed char *b;
auto signed r;
auto signed(__cdecl*f)(signed char *argp,...);
auto signed(__cdecl*(fn[]))(signed char *argp,...) = {
f0,f1,0x00,
};
r = (0x01); // 0 or 1
r = (r%(0x02)); // by the number of functions
f = (*(r+(fn)));
b = (0x00);
r = f("1st","2nd","3rd","4th","5th",b);
if(!r) printf("Oops..\n");
return(0x00);
}
Remarks:
Add
# define __cdecl __attribute__((ms_abi))
and remove
# define __cdecl
if you compile the above source code with GCC on WSL.