Connecting Tech Pros Worldwide Forums | Help | Site Map

Confusion over main function syntax

Mark Hobley
Guest
 
Posts: n/a
#1: Jun 27 '08
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
Guest
 
Posts: n/a
#2: Jun 27 '08

re: Confusion over main function syntax


Mark Hobley wrote:
Quote:
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.
Quote:
Why is the second syntax sometimes used?
>
Probably personal preference.
Quote:
Do the differences effect the build in any way?
>
No.
Quote:
Are both variants legal and correct in ANSI C (89)?
>
Yes.

--
Ian Collins.
Eric Sosman
Guest
 
Posts: n/a
#3: Jun 27 '08

re: Confusion over main function syntax


Mark Hobley wrote:
Quote:
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/>.
Quote:
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."
Quote:
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.
Quote:
Are both variants legal and correct in ANSI C (89)?
Yes, and in all subsequent Standards, too.

--
Eric Sosman
esosman@ieee-dot-org.invalid
Richard Tobin
Guest
 
Posts: n/a
#4: Jun 27 '08

re: Confusion over main function syntax


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

-- Richard
--
:wq
Closed Thread