Saturday, January 28, 2006

geeky Hello World application

Today's C++ puzzle was originally developed together with my student assistant Juergen as a geeky idea on how to write a full blown Java application without a main method. The same "technology" does work on C++ as well but you have to fake the linker with a symbol main to translate the program. You can do this by providing a global integer variable main instead of a main method.

Now for today's puzzle: Write a Hello World application without a function main. What is the drawback of this "technology" to write applications, apart from the obvious one that it is a ugly hack?

1 comment:

Unknown said...

Well, I could see one just declaring an

int main = (int) &MyClass:MyStaticFunction;

Which, assuming int is the same size as a function pointer on your particular platform, would alias main to point to MyMainFunction.

Is that what you're hinting at?

I don't think one could use a functor to do this on most platforms, and directly implementing WINMAIN or __start on other platforms is probably not what you meant either ... ?