www.digitalmars.com         C & C++   DMDScript  

D - is it realy possible without preprocessor?

reply bobef <bobef_member pathlink.com> writes:
imagine this case:

#define entry(myappclass) int main(int argc,char **argv){app=new
myappclass;return my_main(argc,argv);}

i'm doing a class library and i don't want user to make main function
it seems to me it is impossible without a #define

templates need to be created somewhre (main)
alises work only for data types
and it is not good to do it in the constructor of [myappclass]
because all global objects need to be constructed first...
Apr 23 2004
next sibling parent Norbert Nemec <Norbert.Nemec gmx.de> writes:
There are lots of thing that cannot be done without preprocessor. The
question is, whether they really *need* to be done. Why make a hassle over
three lines that users have to write? Anyone using D expects to write a
main routine anyway.


bobef wrote:

 imagine this case:
 
 #define entry(myappclass) int main(int argc,char **argv){app=new
 myappclass;return my_main(argc,argv);}
 
 i'm doing a class library and i don't want user to make main function
 it seems to me it is impossible without a #define
 
 templates need to be created somewhre (main)
 alises work only for data types
 and it is not good to do it in the constructor of [myappclass]
 because all global objects need to be constructed first...
Apr 23 2004
prev sibling parent Carlos Santander B. <Carlos_member pathlink.com> writes:
In article <c6buno$1tae$1 digitaldaemon.com>, bobef says...
imagine this case:

#define entry(myappclass) int main(int argc,char **argv){app=new
myappclass;return my_main(argc,argv);}

i'm doing a class library and i don't want user to make main function
it seems to me it is impossible without a #define

templates need to be created somewhre (main)
alises work only for data types
and it is not good to do it in the constructor of [myappclass]
because all global objects need to be constructed first...
Have the user write this: static this() { entry!(SomeClass)(); } And define somewhere else: template entry (T) { void entry() { app=new T; } } int main(char [][] args) { return my_main(args); } Although I bet that main could be replaced by whatever my_main does. BTW, I didn't test the code. ------------------- Carlos Santander B.
Apr 23 2004