--- In [email protected], ashish sarode <[EMAIL PROTECTED]> wrote:
>
> Hi,
>
> I am not sure about this but i think writting default argument in
the macro might solve your problem. Please give a try to this
>
> #define main(a,b) main(a=0,b=0){
> my_Function();
> user_main(argc,argv);
> }
> user_main(a,b)
>
> There might be mistakes in the code i have provided - but i think
i have communicated the idea.
>
> Best Regards,
> Ashish Sarode
>
>
> RAVI <[EMAIL PROTECTED]> wrote:
> --- In [email protected], "Paul Herring"
<pauljherring@> wrote:
> >
> > On 9/25/07, RAVI <rachel_thati@> wrote:
> > > Hello everybody,
> > >
> > > I am writing an application where I will call my function first
before
> > > the executing the user's main function.
> > > I would like to write my our main function from which the user main
> > > function has to be called.
> > >
> > > i am trying to #define the main function like this:
> > >
> > > #define main(a,b) main(a,b){
> > > my_Function();
> > > user_main(argc,argv);
> > > }
> > > user_main(a,b)
> > >
> > >
> > > This works fine if the user is writing his/her main function as
> > > int main(int argc,char *argv[])
> > > but what if the user is writng main function as
> > > int main()
> > > simply without any arguments.
> > >
> > > How do I #define the user main fuction so that any type of user main
> > > function can be replaced .
> >
> > Your solution is wrong.
> >
> > Tell your users to write their function to match
> >
> > int user_function(int, char**)
> >
> > even if they don't intend to use them, and then you write
> >
> > int main(int argc, char** argv){
> > your_function(argc, argv);
> > return user_function(argc, argv);
> > }
> >
> > and don't use the defines at all.
> >
> >
> > --
> > PJH
> > "Statistics are like a bikini. What they reveal is suggestive, but
> > what they conceal is vital"
> > -- Aaron Levenstein
> >
> Thanks for that response.
>
> I can't force my users to write that format of main function.
>
> I am intended to allow them to write the main function in any of the
> two possible forms, still I have to achieve my task.
>
> What makes my solution wrong ?
> I wanted to see the solution with this approach only.
> what makes #defines wrong in my solution?
>
> Can't I find a solution in this way?
>
> --
> Ravi.T
>
>
>
>
>
>
>
> ---------------------------------
> Explore your hobbies and interests. Click here to begin.
>
> [Non-text portions of this message have been removed]
>
Thanks Ashish.
But I need to resolve variable arguments and also retain the name s
of arguments.
Lets see this scenario:
If I define using variable arguments like this:
#define main(...) main(int argc, char* argv[]){
my_function();
user_main(argc,argv);
}
user_main(int
argc,char* argv[])
there is a big problem.
lets say my user program is like this:
int main(int x,char* y[])
{
int i;
if( x < 2 )
printf("No args\n");
else{
printf("u have given %d argumets those are: \n",x);
for(i=0;i<x;i++)
printf("%s\n",y[i]);
}
}
Thats all , Our assumption will never work. Compiler reports errors:
UNDEFINED VARIABLES x and y.
We should retain the variable names if the user is using and also
handle the main functions not having any arguments.
--
Ravi.T