Thread overview
is it realy possible without preprocessor?
Apr 23, 2004
bobef
Apr 23, 2004
Norbert Nemec
April 23, 2004
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...


April 23, 2004
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...

April 23, 2004
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.