Confusion over main function syntax

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Mark Hobley

    Confusion over main function syntax

    A program typically has a main function defined as follows:

    int main (int argc, char *argv[]) {
    /* blah blah */
    }

    I have noticed that some programs use the syntax:

    int main (int argc, char **argv) {
    /* blah blah */
    }

    Is there a difference between the two methods above, or are they
    completely interchangeable ? Could I change the startup line
    from the second example to the startup line in the first without any
    effects on the programs behaviour?

    Why is the second syntax sometimes used?

    Do the differences effect the build in any way?

    Are both variants legal and correct in ANSI C (89)?

    Thanks in advance to anyone who can help.

    Mark.

    --
    Mark Hobley,
    393 Quinton Road West,
    Quinton, BIRMINGHAM.
    B32 1QE.
  • Ian Collins

    #2
    Re: Confusion over main function syntax

    Mark Hobley wrote:
    A program typically has a main function defined as follows:
    >
    int main (int argc, char *argv[]) {
    /* blah blah */
    }
    >
    I have noticed that some programs use the syntax:
    >
    int main (int argc, char **argv) {
    /* blah blah */
    }
    >
    Is there a difference between the two methods above, or are they
    completely interchangeable ? Could I change the startup line
    from the second example to the startup line in the first without any
    effects on the programs behaviour?
    >
    Yes.
    Why is the second syntax sometimes used?
    >
    Probably personal preference.
    Do the differences effect the build in any way?
    >
    No.
    Are both variants legal and correct in ANSI C (89)?
    >
    Yes.

    --
    Ian Collins.

    Comment

    • Eric Sosman

      #3
      Re: Confusion over main function syntax

      Mark Hobley wrote:
      A program typically has a main function defined as follows:
      >
      int main (int argc, char *argv[]) {
      /* blah blah */
      }
      >
      I have noticed that some programs use the syntax:
      >
      int main (int argc, char **argv) {
      /* blah blah */
      }
      >
      Is there a difference between the two methods above, or are they
      completely interchangeable ? Could I change the startup line
      from the second example to the startup line in the first without any
      effects on the programs behaviour?
      This is Question 6.4 in the comp.lang.c Frequently
      Asked Questions (FAQ) list, <http://www.c-faq.com/>.
      Why is the second syntax sometimes used?
      Because the first syntax sometimes isn't? They mean
      the same thing, so it's just a matter of the programmer's
      own preference as to which is more expressive. You can
      write `int a; int b; int c;' or `int a, b, c;'. "You can
      call me Ray, or you can call me Jay," but either way it
      means "Johnson."
      Do the differences effect the build in any way?
      (You mean "affect," not "effect.") Probably not, since
      the two mean the same thing. Still, compilers are always at
      liberty to emit non-required diagnostic messages, and it's
      conceivable that some compiler somewhere might squawk about
      one form but not about the other.
      Are both variants legal and correct in ANSI C (89)?
      Yes, and in all subsequent Standards, too.

      --
      Eric Sosman
      esosman@ieee-dot-org.invalid

      Comment

      • Richard Tobin

        #4
        Re: Confusion over main function syntax

        In article <2u4fe5-g6s.ln1@neptune .markhobley.yi. org>,
        Mark Hobley <markhobley@hot pop.donottypeth isbit.comwrote:
        int main (int argc, char *argv[]) {
        int main (int argc, char **argv) {
        This equivalence isn't specific to main(), it applies to all
        arrays passed to functions.

        -- Richard
        --
        :wq

        Comment

        Working...