how #define a main() function and call our own main function?

Discussion in 'C Programming' started by ravi, Sep 25, 2007.

  1. ravi

    ravi Guest

    Hello everybody,

    I am writing a small application which does some work before the user
    main function starts execution.


    I am trying to #define the main function.

    But the problem is that,

    the main () function by user may be of different types
    1. main()
    2.main(int argc)
    3. main(int argc, char *argv[])

    How to #define all these three possibilities. And there is not
    guarantee that the user is going to use the same names "argc &argv"
    all the times. we need also know the argments name if needed to access
    them.

    I am trying to do this.
    #define main(a,b) main(a,b){
    my_function();
    user_main(argc,argv);
    }
    user_main(a,b)

    But this will not work if we have to deal with above listed 3 cases.
    and also the agrument names problem.

    Can I have some suggestions on this?

    Thanks in advance.

    --
    Ravi.T
    ravi, Sep 25, 2007
    #1
    1. Advertising

  2. ravi

    user923005 Guest

    On Sep 24, 10:03 pm, ravi <> wrote:
    > Hello everybody,
    >
    > I am writing a small application which does some work before the user
    > main function starts execution.
    >
    > I am trying to #define the main function.
    >
    > But the problem is that,
    >
    > the main () function by user may be of different types
    > 1. main()
    > 2.main(int argc)


    #2 is strictly not allowed by the language.

    > 3. main(int argc, char *argv[])
    >
    > How to #define all these three possibilities. And there is not
    > guarantee that the user is going to use the same names "argc &argv"
    > all the times. we need also know the argments name if needed to access
    > them.
    >
    > I am trying to do this.
    > #define main(a,b) main(a,b){
    > my_function();
    > user_main(argc,argv);
    > }
    > user_main(a,b)
    >
    > But this will not work if we have to deal with above listed 3 cases.
    > and also the agrument names problem.
    >
    > Can I have some suggestions on this?


    You only need this one:

    int main(int argc, char **argv);

    If there are no arguments, then argc will be zero or 1.
    user923005, Sep 25, 2007
    #2
    1. Advertising

  3. ravi

    ravi Guest

    On Sep 25, 10:29 am, user923005 <> wrote:
    > On Sep 24, 10:03 pm, ravi <> wrote:
    >
    > > Hello everybody,

    >
    > > I am writing a small application which does some work before the user
    > > main function starts execution.

    >
    > > I am trying to #define the main function.

    >
    > > But the problem is that,

    >
    > > the main () function by user may be of different types
    > > 1. main()
    > > 2.main(int argc)

    >
    > #2 is strictly not allowed by the language.
    >
    >
    >
    > > 3. main(int argc, char *argv[])

    >
    > > How to #define all these three possibilities. And there is not
    > > guarantee that the user is going to use the same names "argc &argv"
    > > all the times. we need also know the argments name if needed to access
    > > them.

    >
    > > I am trying to do this.
    > > #define main(a,b) main(a,b){
    > > my_function();
    > > user_main(argc,argv);
    > > }
    > > user_main(a,b)

    >
    > > But this will not work if we have to deal with above listed 3 cases.
    > > and also the agrument names problem.

    >
    > > Can I have some suggestions on this?

    >
    > You only need this one:
    >
    > int main(int argc, char **argv);
    >
    > If there are no arguments, then argc will be zero or 1.


    Can you please try this program:
    example.c:
    int main(int argc)
    {
    printf("Hello World\n");
    return 0;
    }
    I am able to compile and run this.
    ravi, Sep 25, 2007
    #3
  4. ravi

    user923005 Guest

    On Sep 24, 10:49 pm, ravi <> wrote:
    > On Sep 25, 10:29 am, user923005 <> wrote:
    >
    >
    >
    >
    >
    > > On Sep 24, 10:03 pm, ravi <> wrote:

    >
    > > > Hello everybody,

    >
    > > > I am writing a small application which does some work before the user
    > > > main function starts execution.

    >
    > > > I am trying to #define the main function.

    >
    > > > But the problem is that,

    >
    > > > the main () function by user may be of different types
    > > > 1. main()
    > > > 2.main(int argc)

    >
    > > #2 is strictly not allowed by the language.

    >
    > > > 3. main(int argc, char *argv[])

    >
    > > > How to #define all these three possibilities. And there is not
    > > > guarantee that the user is going to use the same names "argc &argv"
    > > > all the times. we need also know the argments name if needed to access
    > > > them.

    >
    > > > I am trying to do this.
    > > > #define main(a,b) main(a,b){
    > > > my_function();
    > > > user_main(argc,argv);
    > > > }
    > > > user_main(a,b)

    >
    > > > But this will not work if we have to deal with above listed 3 cases.
    > > > and also the agrument names problem.

    >
    > > > Can I have some suggestions on this?

    >
    > > You only need this one:

    >
    > > int main(int argc, char **argv);

    >
    > > If there are no arguments, then argc will be zero or 1.

    >
    > Can you please try this program:
    > example.c:
    > int main(int argc)
    > {
    > printf("Hello World\n");
    > return 0;}
    >
    > I am able to compile and run this


    That's funny. It made demons fly out of my nose. I guess I should
    have paid attention to my error checkers:

    C:\tmp>splint t.c
    Splint 3.1.1 --- 12 Mar 2007

    t.c(1,17): Function main declared with 1 arg, should have 2 (int argc,
    char
    *argv[])
    The function main does not match the expected type. (Use -maintype
    to inhibit
    warning)
    t.c: (in function main)
    t.c(1,26): Parameter argc not used
    A function parameter is not used in the body of the function. If the
    argument
    is needed for type compatibility or future plans, use /*@unused@*/
    in the
    argument declaration. (Use -paramuse to inhibit warning)

    Finished checking --- 2 code warnings

    C:\tmp>type t.c
    int main(int argc)
    {
    printf("Hello World\n");
    return 0;
    }

    C:\tmp>lin t.c

    C:\tmp>"C:\Lint\Lint-nt" +v -i"C:\Lint" std.lnt -os(_LINT.TMP) t.c
    PC-lint for C/C++ (NT) Vers. 8.00u, Copyright Gimpel Software
    1985-2006

    --- Module: t.c (C)

    C:\tmp>type _LINT.TMP | more

    --- Module: t.c (C)
    _
    printf("Hello World\n");
    t.c(3) : Info 718: Symbol 'printf' undeclared, assumed to return int
    t.c(3) : Info 746: call to function 'printf()' not made in the
    presence of a
    prototype
    _
    }
    t.c(6) : Info 715: Symbol 'argc' (line 1) not referenced
    t.c(1) : Info 830: Location cited in prior message
    _
    }
    t.c(6) : Note 952: Parameter 'argc' (line 1) could be declared const
    --- Eff.
    C++ 3rd Ed. item 3
    t.c(1) : Info 830: Location cited in prior message

    --- Global Wrap-up

    Warning 526: Symbol 'printf()' (line 3, file t.c) not defined
    t.c(3) : Info 830: Location cited in prior message
    Warning 628: no argument information provided for function
    'printf()' (line 3,
    file t.c)
    t.c(3) : Info 830: Location cited in prior message

    ---
    output placed in _LINT.TMP
    user923005, Sep 25, 2007
    #4
  5. ravi

    user923005 Guest

    On Sep 24, 10:49 pm, ravi <> wrote:
    > On Sep 25, 10:29 am, user923005 <> wrote:
    >
    >
    >
    >
    >
    > > On Sep 24, 10:03 pm, ravi <> wrote:

    >
    > > > Hello everybody,

    >
    > > > I am writing a small application which does some work before the user
    > > > main function starts execution.

    >
    > > > I am trying to #define the main function.

    >
    > > > But the problem is that,

    >
    > > > the main () function by user may be of different types
    > > > 1. main()
    > > > 2.main(int argc)

    >
    > > #2 is strictly not allowed by the language.

    >
    > > > 3. main(int argc, char *argv[])

    >
    > > > How to #define all these three possibilities. And there is not
    > > > guarantee that the user is going to use the same names "argc &argv"
    > > > all the times. we need also know the argments name if needed to access
    > > > them.

    >
    > > > I am trying to do this.
    > > > #define main(a,b) main(a,b){
    > > > my_function();
    > > > user_main(argc,argv);
    > > > }
    > > > user_main(a,b)

    >
    > > > But this will not work if we have to deal with above listed 3 cases.
    > > > and also the agrument names problem.

    >
    > > > Can I have some suggestions on this?

    >
    > > You only need this one:

    >
    > > int main(int argc, char **argv);

    >
    > > If there are no arguments, then argc will be zero or 1.

    >
    > Can you please try this program:
    > example.c:
    > int main(int argc)
    > {
    > printf("Hello World\n");
    > return 0;}
    >
    > I am able to compile and run this


    >From the C FAQ:


    11.12a: What's the correct declaration of main()?

    A: Either int main(), int main(void), or int main(int argc,
    char *argv[]) (with alternate spellings of argc and *argv[]
    obviously allowed). See also questions 11.12b to 11.15 below.

    References: ISO Sec. 5.1.2.2.1, Sec. G.5.1; H&S Sec. 20.1 p.
    416; CT&P Sec. 3.10 pp. 50-51.
    user923005, Sep 25, 2007
    #5
  6. ravi

    ravi Guest

    On Sep 25, 11:14 am, user923005 <> wrote:
    > On Sep 24, 10:49 pm, ravi <> wrote:
    >
    >
    >
    > > On Sep 25, 10:29 am, user923005 <> wrote:

    >
    > > > On Sep 24, 10:03 pm, ravi <> wrote:

    >
    > > > > Hello everybody,

    >
    > > > > I am writing a small application which does some work before the user
    > > > > main function starts execution.

    >
    > > > > I am trying to #define the main function.

    >
    > > > > But the problem is that,

    >
    > > > > the main () function by user may be of different types
    > > > > 1. main()
    > > > > 2.main(int argc)

    >
    > > > #2 is strictly not allowed by the language.

    >
    > > > > 3. main(int argc, char *argv[])

    >
    > > > > How to #define all these three possibilities. And there is not
    > > > > guarantee that the user is going to use the same names "argc &argv"
    > > > > all the times. we need also know the argments name if needed to access
    > > > > them.

    >
    > > > > I am trying to do this.
    > > > > #define main(a,b) main(a,b){
    > > > > my_function();
    > > > > user_main(argc,argv);
    > > > > }
    > > > > user_main(a,b)

    >
    > > > > But this will not work if we have to deal with above listed 3 cases.
    > > > > and also the agrument names problem.

    >
    > > > > Can I have some suggestions on this?

    >
    > > > You only need this one:

    >
    > > > int main(int argc, char **argv);

    >
    > > > If there are no arguments, then argc will be zero or 1.

    >
    > > Can you please try this program:
    > > example.c:
    > > int main(int argc)
    > > {
    > > printf("Hello World\n");
    > > return 0;}

    >
    > > I am able to compile and run this

    >
    > That's funny. It made demons fly out of my nose. I guess I should
    > have paid attention to my error checkers:
    >
    > C:\tmp>splint t.c
    > Splint 3.1.1 --- 12 Mar 2007
    >
    > t.c(1,17): Function main declared with 1 arg, should have 2 (int argc,
    > char
    > *argv[])
    > The function main does not match the expected type. (Use -maintype
    > to inhibit
    > warning)
    > t.c: (in function main)
    > t.c(1,26): Parameter argc not used
    > A function parameter is not used in the body of the function. If the
    > argument
    > is needed for type compatibility or future plans, use /*@unused@*/
    > in the
    > argument declaration. (Use -paramuse to inhibit warning)
    >
    > Finished checking --- 2 code warnings
    >
    > C:\tmp>type t.c
    > int main(int argc)
    > {
    > printf("Hello World\n");
    > return 0;
    >
    > }
    >
    > C:\tmp>lin t.c
    >
    > C:\tmp>"C:\Lint\Lint-nt" +v -i"C:\Lint" std.lnt -os(_LINT.TMP) t.c
    > PC-lint for C/C++ (NT) Vers. 8.00u, Copyright Gimpel Software
    > 1985-2006
    >
    > --- Module: t.c (C)
    >
    > C:\tmp>type _LINT.TMP | more
    >
    > --- Module: t.c (C)
    > _
    > printf("Hello World\n");
    > t.c(3) : Info 718: Symbol 'printf' undeclared, assumed to return int
    > t.c(3) : Info 746: call to function 'printf()' not made in the
    > presence of a
    > prototype
    > _}
    >
    > t.c(6) : Info 715: Symbol 'argc' (line 1) not referenced
    > t.c(1) : Info 830: Location cited in prior message
    > _}
    >
    > t.c(6) : Note 952: Parameter 'argc' (line 1) could be declared const
    > --- Eff.
    > C++ 3rd Ed. item 3
    > t.c(1) : Info 830: Location cited in prior message
    >
    > --- Global Wrap-up
    >
    > Warning 526: Symbol 'printf()' (line 3, file t.c) not defined
    > t.c(3) : Info 830: Location cited in prior message
    > Warning 628: no argument information provided for function
    > 'printf()' (line 3,
    > file t.c)
    > t.c(3) : Info 830: Location cited in prior message
    >
    > ---
    > output placed in _LINT.TMP


    I have compiled it using gcc. But if I use splint to compile , i get
    the same as u have written.
    I assume here the user going for gcc instead of any other.

    Why is gcc not reporting the same when splint reports it. I mean if
    its not the usage of the language gcc should also report that warning
    by defaultl.
    ravi, Sep 25, 2007
    #6
  7. ravi

    user923005 Guest

    On Sep 24, 11:30 pm, ravi <> wrote:
    > On Sep 25, 11:14 am, user923005 <> wrote:
    >
    >
    >
    >
    >
    > > On Sep 24, 10:49 pm, ravi <> wrote:

    >
    > > > On Sep 25, 10:29 am, user923005 <> wrote:

    >
    > > > > On Sep 24, 10:03 pm, ravi <> wrote:

    >
    > > > > > Hello everybody,

    >
    > > > > > I am writing a small application which does some work before the user
    > > > > > main function starts execution.

    >
    > > > > > I am trying to #define the main function.

    >
    > > > > > But the problem is that,

    >
    > > > > > the main () function by user may be of different types
    > > > > > 1. main()
    > > > > > 2.main(int argc)

    >
    > > > > #2 is strictly not allowed by the language.

    >
    > > > > > 3. main(int argc, char *argv[])

    >
    > > > > > How to #define all these three possibilities. And there is not
    > > > > > guarantee that the user is going to use the same names "argc &argv"
    > > > > > all the times. we need also know the argments name if needed to access
    > > > > > them.

    >
    > > > > > I am trying to do this.
    > > > > > #define main(a,b) main(a,b){
    > > > > > my_function();
    > > > > > user_main(argc,argv);
    > > > > > }
    > > > > > user_main(a,b)

    >
    > > > > > But this will not work if we have to deal with above listed 3 cases.
    > > > > > and also the agrument names problem.

    >
    > > > > > Can I have some suggestions on this?

    >
    > > > > You only need this one:

    >
    > > > > int main(int argc, char **argv);

    >
    > > > > If there are no arguments, then argc will be zero or 1.

    >
    > > > Can you please try this program:
    > > > example.c:
    > > > int main(int argc)
    > > > {
    > > > printf("Hello World\n");
    > > > return 0;}

    >
    > > > I am able to compile and run this

    >
    > > That's funny. It made demons fly out of my nose. I guess I should
    > > have paid attention to my error checkers:

    >
    > > C:\tmp>splint t.c
    > > Splint 3.1.1 --- 12 Mar 2007

    >
    > > t.c(1,17): Function main declared with 1 arg, should have 2 (int argc,
    > > char
    > > *argv[])
    > > The function main does not match the expected type. (Use -maintype
    > > to inhibit
    > > warning)
    > > t.c: (in function main)
    > > t.c(1,26): Parameter argc not used
    > > A function parameter is not used in the body of the function. If the
    > > argument
    > > is needed for type compatibility or future plans, use /*@unused@*/
    > > in the
    > > argument declaration. (Use -paramuse to inhibit warning)

    >
    > > Finished checking --- 2 code warnings

    >
    > > C:\tmp>type t.c
    > > int main(int argc)
    > > {
    > > printf("Hello World\n");
    > > return 0;

    >
    > > }

    >
    > > C:\tmp>lin t.c

    >
    > > C:\tmp>"C:\Lint\Lint-nt" +v -i"C:\Lint" std.lnt -os(_LINT.TMP) t.c
    > > PC-lint for C/C++ (NT) Vers. 8.00u, Copyright Gimpel Software
    > > 1985-2006

    >
    > > --- Module: t.c (C)

    >
    > > C:\tmp>type _LINT.TMP | more

    >
    > > --- Module: t.c (C)
    > > _
    > > printf("Hello World\n");
    > > t.c(3) : Info 718: Symbol 'printf' undeclared, assumed to return int
    > > t.c(3) : Info 746: call to function 'printf()' not made in the
    > > presence of a
    > > prototype
    > > _}

    >
    > > t.c(6) : Info 715: Symbol 'argc' (line 1) not referenced
    > > t.c(1) : Info 830: Location cited in prior message
    > > _}

    >
    > > t.c(6) : Note 952: Parameter 'argc' (line 1) could be declared const
    > > --- Eff.
    > > C++ 3rd Ed. item 3
    > > t.c(1) : Info 830: Location cited in prior message

    >
    > > --- Global Wrap-up

    >
    > > Warning 526: Symbol 'printf()' (line 3, file t.c) not defined
    > > t.c(3) : Info 830: Location cited in prior message
    > > Warning 628: no argument information provided for function
    > > 'printf()' (line 3,
    > > file t.c)
    > > t.c(3) : Info 830: Location cited in prior message

    >
    > > ---
    > > output placed in _LINT.TMP

    >
    > I have compiled it using gcc. But if I use splint to compile , i get
    > the same as u have written.
    > I assume here the user going for gcc instead of any other.
    >
    > Why is gcc not reporting the same when splint reports it. I mean if
    > its not the usage of the language gcc should also report that warning
    > by defaultl.


    There are some things that require a warning and others that don't. C
    let's you shoot yourself in the foot sometimes. However, in this case
    you were simply using the tool incorrectly:

    dcorbit@DCORBIT64 /c/tmp
    $ gcc -W -Wall -ansi -pedantic t.c
    t.c:2: warning: 'main' takes only zero or two arguments
    t.c: In function 'main':
    t.c:3: warning: implicit declaration of function 'printf'
    t.c:3: warning: incompatible implicit declaration of built-in function
    'printf'
    t.c: At top level:
    t.c:1: warning: unused parameter 'argc'
    user923005, Sep 25, 2007
    #7
  8. ravi

    ravi Guest

    On Sep 25, 11:37 am, user923005 <> wrote:
    > On Sep 24, 11:30 pm, ravi <> wrote:
    >
    >
    >
    > > On Sep 25, 11:14 am, user923005 <> wrote:

    >
    > > > On Sep 24, 10:49 pm, ravi <> wrote:

    >
    > > > > On Sep 25, 10:29 am, user923005 <> wrote:

    >
    > > > > > On Sep 24, 10:03 pm, ravi <> wrote:

    >
    > > > > > > Hello everybody,

    >
    > > > > > > I am writing a small application which does some work before the user
    > > > > > > main function starts execution.

    >
    > > > > > > I am trying to #define the main function.

    >
    > > > > > > But the problem is that,

    >
    > > > > > > the main () function by user may be of different types
    > > > > > > 1. main()
    > > > > > > 2.main(int argc)

    >
    > > > > > #2 is strictly not allowed by the language.

    >
    > > > > > > 3. main(int argc, char *argv[])

    >
    > > > > > > How to #define all these three possibilities. And there is not
    > > > > > > guarantee that the user is going to use the same names "argc &argv"
    > > > > > > all the times. we need also know the argments name if needed to access
    > > > > > > them.

    >
    > > > > > > I am trying to do this.
    > > > > > > #define main(a,b) main(a,b){
    > > > > > > my_function();
    > > > > > > user_main(argc,argv);
    > > > > > > }
    > > > > > > user_main(a,b)

    >
    > > > > > > But this will not work if we have to deal with above listed 3 cases.
    > > > > > > and also the agrument names problem.

    >
    > > > > > > Can I have some suggestions on this?

    >
    > > > > > You only need this one:

    >
    > > > > > int main(int argc, char **argv);

    >
    > > > > > If there are no arguments, then argc will be zero or 1.

    >
    > > > > Can you please try this program:
    > > > > example.c:
    > > > > int main(int argc)
    > > > > {
    > > > > printf("Hello World\n");
    > > > > return 0;}

    >
    > > > > I am able to compile and run this

    >
    > > > That's funny. It made demons fly out of my nose. I guess I should
    > > > have paid attention to my error checkers:

    >
    > > > C:\tmp>splint t.c
    > > > Splint 3.1.1 --- 12 Mar 2007

    >
    > > > t.c(1,17): Function main declared with 1 arg, should have 2 (int argc,
    > > > char
    > > > *argv[])
    > > > The function main does not match the expected type. (Use -maintype
    > > > to inhibit
    > > > warning)
    > > > t.c: (in function main)
    > > > t.c(1,26): Parameter argc not used
    > > > A function parameter is not used in the body of the function. If the
    > > > argument
    > > > is needed for type compatibility or future plans, use /*@unused@*/
    > > > in the
    > > > argument declaration. (Use -paramuse to inhibit warning)

    >
    > > > Finished checking --- 2 code warnings

    >
    > > > C:\tmp>type t.c
    > > > int main(int argc)
    > > > {
    > > > printf("Hello World\n");
    > > > return 0;

    >
    > > > }

    >
    > > > C:\tmp>lin t.c

    >
    > > > C:\tmp>"C:\Lint\Lint-nt" +v -i"C:\Lint" std.lnt -os(_LINT.TMP) t.c
    > > > PC-lint for C/C++ (NT) Vers. 8.00u, Copyright Gimpel Software
    > > > 1985-2006

    >
    > > > --- Module: t.c (C)

    >
    > > > C:\tmp>type _LINT.TMP | more

    >
    > > > --- Module: t.c (C)
    > > > _
    > > > printf("Hello World\n");
    > > > t.c(3) : Info 718: Symbol 'printf' undeclared, assumed to return int
    > > > t.c(3) : Info 746: call to function 'printf()' not made in the
    > > > presence of a
    > > > prototype
    > > > _}

    >
    > > > t.c(6) : Info 715: Symbol 'argc' (line 1) not referenced
    > > > t.c(1) : Info 830: Location cited in prior message
    > > > _}

    >
    > > > t.c(6) : Note 952: Parameter 'argc' (line 1) could be declared const
    > > > --- Eff.
    > > > C++ 3rd Ed. item 3
    > > > t.c(1) : Info 830: Location cited in prior message

    >
    > > > --- Global Wrap-up

    >
    > > > Warning 526: Symbol 'printf()' (line 3, file t.c) not defined
    > > > t.c(3) : Info 830: Location cited in prior message
    > > > Warning 628: no argument information provided for function
    > > > 'printf()' (line 3,
    > > > file t.c)
    > > > t.c(3) : Info 830: Location cited in prior message

    >
    > > > ---
    > > > output placed in _LINT.TMP

    >
    > > I have compiled it using gcc. But if I use splint to compile , i get
    > > the same as u have written.
    > > I assume here the user going for gcc instead of any other.

    >
    > > Why is gcc not reporting the same when splint reports it. I mean if
    > > its not the usage of the language gcc should also report that warning
    > > by defaultl.

    >
    > There are some things that require a warning and others that don't. C
    > let's you shoot yourself in the foot sometimes. However, in this case
    > you were simply using the tool incorrectly:
    >
    > dcorbit@DCORBIT64 /c/tmp
    > $ gcc -W -Wall -ansi -pedantic t.c
    > t.c:2: warning: 'main' takes only zero or two arguments
    > t.c: In function 'main':
    > t.c:3: warning: implicit declaration of function 'printf'
    > t.c:3: warning: incompatible implicit declaration of built-in function
    > 'printf'
    > t.c: At top level:
    > t.c:1: warning: unused parameter 'argc'


    Thnks for that response.

    But my main problem ,

    How to call the user main fuction in my main function, when I don't
    know the user main function either #1 or #3 and with knowing the name
    of the parameters.
    we assume to parse the source code, but there is also an issue that
    main function may be called from a user defined library instead of
    compiling source code.
    ravi, Sep 25, 2007
    #8
  9. ravi

    user923005 Guest

    On Sep 24, 11:47 pm, ravi <> wrote:
    > On Sep 25, 11:37 am, user923005 <> wrote:
    >
    >
    >
    >
    >
    > > On Sep 24, 11:30 pm, ravi <> wrote:

    >
    > > > On Sep 25, 11:14 am, user923005 <> wrote:

    >
    > > > > On Sep 24, 10:49 pm, ravi <> wrote:

    >
    > > > > > On Sep 25, 10:29 am, user923005 <> wrote:

    >
    > > > > > > On Sep 24, 10:03 pm, ravi <> wrote:

    >
    > > > > > > > Hello everybody,

    >
    > > > > > > > I am writing a small application which does some work before the user
    > > > > > > > main function starts execution.

    >
    > > > > > > > I am trying to #define the main function.

    >
    > > > > > > > But the problem is that,

    >
    > > > > > > > the main () function by user may be of different types
    > > > > > > > 1. main()
    > > > > > > > 2.main(int argc)

    >
    > > > > > > #2 is strictly not allowed by the language.

    >
    > > > > > > > 3. main(int argc, char *argv[])

    >
    > > > > > > > How to #define all these three possibilities. And there is not
    > > > > > > > guarantee that the user is going to use the same names "argc &argv"
    > > > > > > > all the times. we need also know the argments name if needed to access
    > > > > > > > them.

    >
    > > > > > > > I am trying to do this.
    > > > > > > > #define main(a,b) main(a,b){
    > > > > > > > my_function();
    > > > > > > > user_main(argc,argv);
    > > > > > > > }
    > > > > > > > user_main(a,b)

    >
    > > > > > > > But this will not work if we have to deal with above listed 3 cases.
    > > > > > > > and also the agrument names problem.

    >
    > > > > > > > Can I have some suggestions on this?

    >
    > > > > > > You only need this one:

    >
    > > > > > > int main(int argc, char **argv);

    >
    > > > > > > If there are no arguments, then argc will be zero or 1.

    >
    > > > > > Can you please try this program:
    > > > > > example.c:
    > > > > > int main(int argc)
    > > > > > {
    > > > > > printf("Hello World\n");
    > > > > > return 0;}

    >
    > > > > > I am able to compile and run this

    >
    > > > > That's funny. It made demons fly out of my nose. I guess I should
    > > > > have paid attention to my error checkers:

    >
    > > > > C:\tmp>splint t.c
    > > > > Splint 3.1.1 --- 12 Mar 2007

    >
    > > > > t.c(1,17): Function main declared with 1 arg, should have 2 (int argc,
    > > > > char
    > > > > *argv[])
    > > > > The function main does not match the expected type. (Use -maintype
    > > > > to inhibit
    > > > > warning)
    > > > > t.c: (in function main)
    > > > > t.c(1,26): Parameter argc not used
    > > > > A function parameter is not used in the body of the function. If the
    > > > > argument
    > > > > is needed for type compatibility or future plans, use /*@unused@*/
    > > > > in the
    > > > > argument declaration. (Use -paramuse to inhibit warning)

    >
    > > > > Finished checking --- 2 code warnings

    >
    > > > > C:\tmp>type t.c
    > > > > int main(int argc)
    > > > > {
    > > > > printf("Hello World\n");
    > > > > return 0;

    >
    > > > > }

    >
    > > > > C:\tmp>lin t.c

    >
    > > > > C:\tmp>"C:\Lint\Lint-nt" +v -i"C:\Lint" std.lnt -os(_LINT.TMP) t.c
    > > > > PC-lint for C/C++ (NT) Vers. 8.00u, Copyright Gimpel Software
    > > > > 1985-2006

    >
    > > > > --- Module: t.c (C)

    >
    > > > > C:\tmp>type _LINT.TMP | more

    >
    > > > > --- Module: t.c (C)
    > > > > _
    > > > > printf("Hello World\n");
    > > > > t.c(3) : Info 718: Symbol 'printf' undeclared, assumed to return int
    > > > > t.c(3) : Info 746: call to function 'printf()' not made in the
    > > > > presence of a
    > > > > prototype
    > > > > _}

    >
    > > > > t.c(6) : Info 715: Symbol 'argc' (line 1) not referenced
    > > > > t.c(1) : Info 830: Location cited in prior message
    > > > > _}

    >
    > > > > t.c(6) : Note 952: Parameter 'argc' (line 1) could be declared const
    > > > > --- Eff.
    > > > > C++ 3rd Ed. item 3
    > > > > t.c(1) : Info 830: Location cited in prior message

    >
    > > > > --- Global Wrap-up

    >
    > > > > Warning 526: Symbol 'printf()' (line 3, file t.c) not defined
    > > > > t.c(3) : Info 830: Location cited in prior message
    > > > > Warning 628: no argument information provided for function
    > > > > 'printf()' (line 3,
    > > > > file t.c)
    > > > > t.c(3) : Info 830: Location cited in prior message

    >
    > > > > ---
    > > > > output placed in _LINT.TMP

    >
    > > > I have compiled it using gcc. But if I use splint to compile , i get
    > > > the same as u have written.
    > > > I assume here the user going for gcc instead of any other.

    >
    > > > Why is gcc not reporting the same when splint reports it. I mean if
    > > > its not the usage of the language gcc should also report that warning
    > > > by defaultl.

    >
    > > There are some things that require a warning and others that don't. C
    > > let's you shoot yourself in the foot sometimes. However, in this case
    > > you were simply using the tool incorrectly:

    >
    > > dcorbit@DCORBIT64 /c/tmp
    > > $ gcc -W -Wall -ansi -pedantic t.c
    > > t.c:2: warning: 'main' takes only zero or two arguments
    > > t.c: In function 'main':
    > > t.c:3: warning: implicit declaration of function 'printf'
    > > t.c:3: warning: incompatible implicit declaration of built-in function
    > > 'printf'
    > > t.c: At top level:
    > > t.c:1: warning: unused parameter 'argc'

    >
    > Thnks for that response.
    >
    > But my main problem ,
    >
    > How to call the user main fuction in my main function, when I don't
    > know the user main function either #1 or #3 and with knowing the name
    > of the parameters.
    > we assume to parse the source code, but there is also an issue that
    > main function may be called from a user defined library instead of
    > compiling source code


    No. The main() function cannot be called from a user defined library.
    The main() function is special. It defines the entry point for
    program startup.
    user923005, Sep 25, 2007
    #9
  10. user923005 said:

    <snip>

    > The main() function cannot be called from a user defined library.


    C&V please.

    > The main() function is special. It defines the entry point for
    > program startup.


    Agreed. Er, so? What stops you putting it in a library? Surely it's all one
    as far as the linker is concerned?

    --
    Richard Heathfield <http://www.cpax.org.uk>
    Email: -http://www. +rjh@
    Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
    "Usenet is a strange place" - dmr 29 July 1999
    Richard Heathfield, Sep 25, 2007
    #10
  11. ravi

    ravi Guest

    On Sep 25, 2:09 pm, Richard Heathfield <> wrote:
    > user923005 said:
    >
    > <snip>
    >
    > > The main() function cannot be called from a user defined library.

    >
    > C&V please.
    >
    > > The main() function is special. It defines the entry point for
    > > program startup.

    >
    > Agreed. Er, so? What stops you putting it in a library? Surely it's all one
    > as far as the linker is concerned?
    >
    > --
    > Richard Heathfield <http://www.cpax.org.uk>
    > Email: -http://www. +rjh@
    > Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
    > "Usenet is a strange place" - dmr 29 July 1999


    I can write a main function in another file and compile it as a
    library link it to another program where there is no main , but some
    sub functions which are called by main. and it works well.
    ravi, Sep 25, 2007
    #11
  12. On Sep 25, 2:17 pm, ravi <> wrote:
    > On Sep 25, 2:09 pm, Richard Heathfield <> wrote:
    >
    >
    >
    >
    >
    > > user923005 said:

    >
    > > <snip>

    >
    > > > The main() function cannot be called from a user defined library.

    >
    > > C&V please.

    >
    > > > The main() function is special. It defines the entry point for
    > > > program startup.

    >
    > > Agreed. Er, so? What stops you putting it in a library? Surely it's all one
    > > as far as the linker is concerned?

    >
    > > --
    > > Richard Heathfield <http://www.cpax.org.uk>
    > > Email: -http://www. +rjh@
    > > Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
    > > "Usenet is a strange place" - dmr 29 July 1999

    >
    > I can write a main function in another file and compile it as a
    > library link it to another program where there is no main , but some
    > sub functions which are called by main. and it works well.- Hide quoted text -
    >
    > - Show quoted text -


    How is this possible ?

    Thx,
    Karthik Balaguru
    karthikbalaguru, Sep 25, 2007
    #12
  13. On 25 sep, 07:03, ravi <> wrote:
    > Hello everybody,
    >
    > I am writing a small application which does some work before the user
    > main function starts execution.
    >
    > I am trying to #define the main function.
    >
    > But the problem is that,
    >
    > the main () function by user may be of different types
    > 1. main()


    not conformant -> int main(void)

    > 2.main(int argc)


    not conformant

    > 3. main(int argc, char *argv[])



    // prelude, already posted here many times
    #define COS_PP_CAT(a,b) COS_PP_CAT_(a,b)
    #define COS_PP_CAT_(a,b) a ## b
    #define COS_PP_NARG_(...) COS_PP_NARG_N_(__VA_ARGS__)
    #define COS_PP_NARG_N_( \
    _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,_46,_47,_48,_49,_50, \
    _51,_52,_53,_54,_55,_56,_57,_58,_59,_60, \
    _61,_62,_63,N,...) N
    #define COS_PP_CAT_NARG(a,...) COS_PP_CAT(a,COS_PP_NARG(__VA_ARGS__))

    // your problem
    #define main(...) \
    COS_PP_CAT_NARG(MAIN_,__VA_ARGS__)(__VA_ARGS__)

    #define MAIN_1() \
    main(void) { \
    int user_main(void); \
    your_main(0,0); \
    user_main(); \
    } \
    int user_main(void)

    #define MAIN_2(ARGC,ARGV) \
    main(int argc, char *argv[]) { \
    int user_main(ARGC,ARGV); \
    your_main(argc,argv); \
    user_main(argc,argv); \
    }
    int user_main(ARGC,ARGV)

    int main(int my_argc, char *my_argc[])
    {
    // code using my_argc and my_argv after your_main() has been called.
    }

    I just wrote this code on the fly, so it is untested and assumes the
    availability of c99 variadic macros.

    I use very often this kind of macro dispatch based on its number of
    argument in COS (macros with optional arguments). PP_NARG has been
    left as posted here in the past, but you could reduce the maximum
    number of argument for you case.

    a+, ld.
    Laurent Deniau, Sep 25, 2007
    #13
  14. ravi

    ravi Guest

    On Sep 25, 3:27 pm, karthikbalaguru <>
    wrote:
    > On Sep 25, 2:17 pm, ravi <> wrote:
    >
    >
    >
    > > On Sep 25, 2:09 pm, Richard Heathfield <> wrote:

    >
    > > > user923005 said:

    >
    > > > <snip>

    >
    > > > > The main() function cannot be called from a user defined library.

    >
    > > > C&V please.

    >
    > > > > The main() function is special. It defines the entry point for
    > > > > program startup.

    >
    > > > Agreed. Er, so? What stops you putting it in a library? Surely it's all one
    > > > as far as the linker is concerned?

    >
    > > > --
    > > > Richard Heathfield <http://www.cpax.org.uk>
    > > > Email: -http://www. +rjh@
    > > > Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
    > > > "Usenet is a strange place" - dmr 29 July 1999

    >
    > > I can write a main function in another file and compile it as a
    > > library link it to another program where there is no main , but some
    > > sub functions which are called by main. and it works well.- Hide quoted text -

    >
    > > - Show quoted text -

    >
    > How is this possible ?
    >
    > Thx,
    > Karthik Balaguru


    give a trial.
    Write a file with main() function calling a function foo().
    main.c :
    int main()
    {
    printf("MAIN\n");
    foo();
    return 0;
    }

    Compile it and make it a library like this:
    > gcc -c main.c -o main.o
    > ar -rc libmain.a main.o


    Now write a file foo.c with foo() function.
    foo.c:
    void foo()
    {
    printf("FOOOOOOOOO\n");
    }
    Now compile like this:
    > gcc foo.c -lmain

    it works and u can try running.

    --
    Ravi.T
    ravi, Sep 25, 2007
    #14
  15. On Sep 25, 3:45 pm, ravi <> wrote:
    > On Sep 25, 3:27 pm, karthikbalaguru <>
    > wrote:
    >
    >
    >
    >
    >
    > > On Sep 25, 2:17 pm, ravi <> wrote:

    >
    > > > On Sep 25, 2:09 pm, Richard Heathfield <> wrote:

    >
    > > > > user923005 said:

    >
    > > > > <snip>

    >
    > > > > > The main() function cannot be called from a user defined library.

    >
    > > > > C&V please.

    >
    > > > > > The main() function is special. It defines the entry point for
    > > > > > program startup.

    >
    > > > > Agreed. Er, so? What stops you putting it in a library? Surely it's all one
    > > > > as far as the linker is concerned?

    >
    > > > > --
    > > > > Richard Heathfield <http://www.cpax.org.uk>
    > > > > Email: -http://www. +rjh@
    > > > > Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
    > > > > "Usenet is a strange place" - dmr 29 July 1999

    >
    > > > I can write a main function in another file and compile it as a
    > > > library link it to another program where there is no main , but some
    > > > sub functions which are called by main. and it works well.- Hide quoted text -

    >
    > > > - Show quoted text -

    >
    > > How is this possible ?

    >
    > > Thx,
    > > Karthik Balaguru

    >
    > give a trial.
    > Write a file with main() function calling a function foo().
    > main.c :
    > int main()
    > {
    > printf("MAIN\n");
    > foo();
    > return 0;
    > }
    >
    > Compile it and make it a library like this:
    > > gcc -c main.c -o main.o
    > > ar -rc libmain.a main.o

    >
    > Now write a file foo.c with foo() function.
    > foo.c:
    > void foo()
    > {
    > printf("FOOOOOOOOO\n");
    > }
    > Now compile like this:
    > > gcc foo.c -lmain

    > it works and u can try running.
    >
    > --
    > Ravi.T- Hide quoted text -
    >
    > - Show quoted text -


    How do u say that it works ?
    What did u get on the console ?

    Karthik Balaguru
    karthikbalaguru, Sep 25, 2007
    #15
  16. ravi

    Richard Guest

    karthikbalaguru <> writes:

    > On Sep 25, 2:17 pm, ravi <> wrote:
    >> On Sep 25, 2:09 pm, Richard Heathfield <> wrote:
    >>
    >>
    >>
    >>
    >>
    >> > user923005 said:

    >>
    >> > <snip>

    >>
    >> > > The main() function cannot be called from a user defined library.

    >>
    >> > C&V please.

    >>
    >> > > The main() function is special. It defines the entry point for
    >> > > program startup.

    >>
    >> > Agreed. Er, so? What stops you putting it in a library? Surely it's all one
    >> > as far as the linker is concerned?

    >>
    >> > --
    >> > Richard Heathfield <http://www.cpax.org.uk>
    >> > Email: -http://www. +rjh@
    >> > Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
    >> > "Usenet is a strange place" - dmr 29 July 1999

    >>
    >> I can write a main function in another file and compile it as a
    >> library link it to another program where there is no main , but some
    >> sub functions which are called by main. and it works well.- Hide quoted text -
    >>
    >> - Show quoted text -

    >
    > How is this possible ?


    You should ask "why would it NOT be possible"?

    If main calls 3 functions - a(),b() and c() what's to stop you linking in
    different versions of these functions for the same main() for different purposes?
    Richard, Sep 25, 2007
    #16
  17. ravi

    ravi Guest

    Thanks Deniau.

    On Sep 25, 3:42 pm, Laurent Deniau <> wrote:
    > On 25 sep, 07:03, ravi <> wrote:
    >
    > > Hello everybody,

    >
    > > I am writing a small application which does some work before the user
    > > main function starts execution.

    >
    > > I am trying to #define the main function.

    >
    > > But the problem is that,

    >
    > > the main () function by user may be of different types
    > > 1. main()

    >
    > not conformant -> int main(void)
    >
    > > 2.main(int argc)

    >
    > not conformant
    >
    > > 3. main(int argc, char *argv[])

    >
    > // prelude, already posted here many times
    > #define COS_PP_CAT(a,b) COS_PP_CAT_(a,b)
    > #define COS_PP_CAT_(a,b) a ## b
    > #define COS_PP_NARG_(...) COS_PP_NARG_N_(__VA_ARGS__)
    > #define COS_PP_NARG_N_( \
    > _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,_46,_47,_48,_49,_50, \
    > _51,_52,_53,_54,_55,_56,_57,_58,_59,_60, \
    > _61,_62,_63,N,...) N



    Where r u calling this macro COS_PP_NARG_N_(__VA_ARGS__).
    How does it replace _1/_2/_3......... how it detects the count of
    arguments?
    please clarify me.


    > #define COS_PP_CAT_NARG(a,...) COS_PP_CAT(a,COS_PP_NARG(__VA_ARGS__))
    >
    > // your problem
    > #define main(...) \
    > COS_PP_CAT_NARG(MAIN_,__VA_ARGS__)(__VA_ARGS__)
    >
    > #define MAIN_1() \
    > main(void) { \
    > int user_main(void); \
    > your_main(0,0); \
    > user_main(); \
    > } \
    > int user_main(void)
    >
    > #define MAIN_2(ARGC,ARGV) \
    > main(int argc, char *argv[]) { \
    > int user_main(ARGC,ARGV); \
    > your_main(argc,argv); \
    > user_main(argc,argv); \
    > }
    > int user_main(ARGC,ARGV)
    >
    > int main(int my_argc, char *my_argc[])
    > {
    > // code using my_argc and my_argv after your_main() has been called.
    >
    > }
    >
    > I just wrote this code on the fly, so it is untested and assumes the
    > availability of c99 variadic macros.
    >
    > I use very often this kind of macro dispatch based on its number of
    > argument in COS (macros with optional arguments). PP_NARG has been
    > left as posted here in the past, but you could reduce the maximum
    > number of argument for you case.
    >
    > a+, ld.
    ravi, Sep 25, 2007
    #17
  18. ravi

    ravi Guest

    Thanks Deniau.

    On Sep 25, 3:42 pm, Laurent Deniau <> wrote:
    > On 25 sep, 07:03, ravi <> wrote:
    >
    > > Hello everybody,

    >
    > > I am writing a small application which does some work before the user
    > > main function starts execution.

    >
    > > I am trying to #define the main function.

    >
    > > But the problem is that,

    >
    > > the main () function by user may be of different types
    > > 1. main()

    >
    > not conformant -> int main(void)
    >
    > > 2.main(int argc)

    >
    > not conformant
    >
    > > 3. main(int argc, char *argv[])

    >
    > // prelude, already posted here many times
    > #define COS_PP_CAT(a,b) COS_PP_CAT_(a,b)
    > #define COS_PP_CAT_(a,b) a ## b
    > #define COS_PP_NARG_(...) COS_PP_NARG_N_(__VA_ARGS__)
    > #define COS_PP_NARG_N_( \
    > _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,_46,_47,_48,_49,_50, \
    > _51,_52,_53,_54,_55,_56,_57,_58,_59,_60, \
    > _61,_62,_63,N,...) N



    Where r u calling this macro COS_PP_NARG_N_(__VA_ARGS__).
    How does it replace _1/_2/_3......... how it detects the count of
    arguments?
    please clarify me.


    > #define COS_PP_CAT_NARG(a,...) COS_PP_CAT(a,COS_PP_NARG(__VA_ARGS__))
    >
    > // your problem
    > #define main(...) \
    > COS_PP_CAT_NARG(MAIN_,__VA_ARGS__)(__VA_ARGS__)
    >
    > #define MAIN_1() \
    > main(void) { \
    > int user_main(void); \
    > your_main(0,0); \
    > user_main(); \
    > } \
    > int user_main(void)
    >
    > #define MAIN_2(ARGC,ARGV) \
    > main(int argc, char *argv[]) { \
    > int user_main(ARGC,ARGV); \
    > your_main(argc,argv); \
    > user_main(argc,argv); \
    > }
    > int user_main(ARGC,ARGV)
    >
    > int main(int my_argc, char *my_argc[])
    > {
    > // code using my_argc and my_argv after your_main() has been called.
    >
    > }
    >
    > I just wrote this code on the fly, so it is untested and assumes the
    > availability of c99 variadic macros.
    >
    > I use very often this kind of macro dispatch based on its number of
    > argument in COS (macros with optional arguments). PP_NARG has been
    > left as posted here in the past, but you could reduce the maximum
    > number of argument for you case.
    >
    > a+, ld.
    ravi, Sep 25, 2007
    #18
  19. On 25 sep, 14:11, ravi <> wrote:
    > Thanks Deniau.
    >
    > On Sep 25, 3:42 pm, Laurent Deniau <> wrote:
    >
    >
    >
    > > On 25 sep, 07:03, ravi <> wrote:

    >
    > > > Hello everybody,

    >
    > > > I am writing a small application which does some work before the user
    > > > main function starts execution.

    >
    > > > I am trying to #define the main function.

    >
    > > > But the problem is that,

    >
    > > > the main () function by user may be of different types
    > > > 1. main()

    >
    > > not conformant -> int main(void)

    >
    > > > 2.main(int argc)

    >
    > > not conformant

    >
    > > > 3. main(int argc, char *argv[])

    >
    > > // prelude, already posted here many times
    > > #define COS_PP_CAT(a,b) COS_PP_CAT_(a,b)
    > > #define COS_PP_CAT_(a,b) a ## b
    > > #define COS_PP_NARG_(...) COS_PP_NARG_N_(__VA_ARGS__)
    > > #define COS_PP_NARG_N_( \
    > > _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,_46,_47,_48,_49,_50, \
    > > _51,_52,_53,_54,_55,_56,_57,_58,_59,_60, \
    > > _61,_62,_63,N,...) N

    >
    > Where r u calling this macro COS_PP_NARG_N_(__VA_ARGS__).
    > How does it replace _1/_2/_3......... how it detects the count of
    > arguments?
    > please clarify me.


    Oops, I usual with untested code some macros are missing (googleing
    this newsgroup or comp.std.c would have pointed my OP on this macro
    some years ago):

    #define COS_PP_NARG(...) COS_PP_NARG_(__VA_ARGS__,COS_PP_REVSEQ_N(),)
    #define COS_PP_REVSEQ_N() \
    63,62,61, \
    60,59,58,57,56,55,54,53,52,51, \
    50,49,48,47,46,45,44,43,42,41, \
    40,39,38,37,36,35,34,33,32,31, \
    30,29,28,27,26,25,24,23,22,21, \
    20,19,18,17,16,15,14,13,12,11, \
    10, 9, 8, 7, 6, 5, 4, 3, 2, 1

    >
    > > #define COS_PP_CAT_NARG(a,...) COS_PP_CAT(a,COS_PP_NARG(__VA_ARGS__))

    >
    > > // your problem
    > > #define main(...) \
    > > COS_PP_CAT_NARG(MAIN_,__VA_ARGS__)(__VA_ARGS__)

    >
    > > #define MAIN_1() \
    > > main(void) { \
    > > int user_main(void); \
    > > your_main(0,0); \
    > > user_main(); \
    > > } \
    > > int user_main(void)

    >
    > > #define MAIN_2(ARGC,ARGV) \
    > > main(int argc, char *argv[]) { \
    > > int user_main(ARGC,ARGV); \
    > > your_main(argc,argv); \
    > > user_main(argc,argv); \
    > > }
    > > int user_main(ARGC,ARGV)

    >
    > > int main(int my_argc, char *my_argc[])
    > > {
    > > // code using my_argc and my_argv after your_main() has been called.

    >
    > > }

    >
    > > I just wrote this code on the fly, so it is untested and assumes the
    > > availability of c99 variadic macros.

    >
    > > I use very often this kind of macro dispatch based on its number of
    > > argument in COS (macros with optional arguments). PP_NARG has been
    > > left as posted here in the past, but you could reduce the maximum
    > > number of argument for you case.

    >
    > > a+, ld.
    Laurent Deniau, Sep 25, 2007
    #19
  20. ravi

    Army1987 Guest

    On Mon, 24 Sep 2007 22:49:37 -0700, ravi wrote:

    > Can you please try this program:
    > example.c:
    > int main(int argc)
    > {
    > printf("Hello World\n");
    > return 0;
    > }
    > I am able to compile and run this.


    Can you please try this program:
    #include <time.h>
    #include <stdio.h>
    size_t main(struct tm argc)
    {
    return puts("hello, world") < 0 ? 0x17 : !mktime(&argc);
    }
    I am able to compile and run this.
    --
    Army1987 (Replace "NOSPAM" with "email")
    A hamburger is better than nothing.
    Nothing is better than eternal happiness.
    Therefore, a hamburger is better than eternal happiness.
    Army1987, Sep 25, 2007
    #20
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jake Barnes
    Replies:
    1
    Views:
    408
    Andy Dingley
    Nov 14, 2005
  2. Pradeep

    Implementing our own providers

    Pradeep, Jun 7, 2006, in forum: ASP .Net
    Replies:
    3
    Views:
    1,795
    john_teague
    Jun 7, 2006
  3. Kamilche

    Our OWN 'Deep C Secrets'

    Kamilche, May 8, 2004, in forum: C Programming
    Replies:
    21
    Views:
    714
    goose
    May 14, 2004
  4. bala
    Replies:
    0
    Views:
    240
  5. robin liu
    Replies:
    3
    Views:
    810
    Robin Liu
    Apr 21, 2006
Loading...

Share This Page