1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
|
#include <cstdlib>
#include <cstdio>
#include <iostream>
#include <stdio.h>
using namespace std;
int before_main(void);
int the_actual_program(void);
/* we need a wrapper function to set it's output to something. if we don't,
we can't let the program have a return value. the reason why is we have to
call exit() as part of a function to give this a return value AND bypass
main(). exit needs to be called with the program's return value. we need
to assign a global value by a function's return value... that function will
execute before main(). this function executes another functions that IS the
actual program bypassing it's own return statement. it never returns, but it
IS called and executes. and that's our goal.
*/
int before_main(void)
{
exit(the_actual_program());
return 0; // this never actually runs. it's here so we can assign before_main()'s value to something
}
int foo_bar = before_main(); // here we make a global assignment which must occur before main()
#define decode(s,t,u,m,p,e,d) m##s##u##t
#define begin decode(a,n,i,m,a,t,e)
int begin(int argc, char *argv[])
{
puts("We're inside of Main()"); // this never runs.
getchar(); // this is a pause so tha twhen you run the program, it'll be proven this ever pops up.
return foo_bar; // we put this here so the compiler doesn't complain we never use it.
}
int the_actual_program(void)
{
puts("We're NOT inside of Main()"); // this WILL run
getchar(); // a pause.
return 0; // yes, this is the program's return value due to exit() in the wrapper function
}
|