473,395 Members | 1,403 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

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.
Jun 27 '08 #1
3 1461
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.
Jun 27 '08 #2
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
es*****@ieee-dot-org.invalid
Jun 27 '08 #3
In article <2u************@neptune.markhobley.yi.org>,
Mark Hobley <ma********@hotpop.donottypethisbit.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
Jun 27 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

38
by: Grant Edwards | last post by:
In an interview at http://acmqueue.com/modules.php?name=Content&pa=showpage&pid=273 Alan Kay said something I really liked, and I think it applies equally well to Python as well as the languages...
4
by: Chris Mabee | last post by:
Hello all, and Merry Christmas, I'm having a problem understanding an example of an array based implementation of a stack in a textbook of mine. The code in question is written below. The syntax...
8
by: Z D | last post by:
Hello, I'm having a strange problem that is probably due to my lack of understanding of how threading & COM Interop works in a WinForms.NET application. Here's the situation: I have a 3rd...
39
by: Martin Jørgensen | last post by:
Hi, I'm relatively new with C-programming and even though I've read about pointers and arrays many times, it's a topic that is a little confusing to me - at least at this moment: ---- 1)...
3
by: Scott | last post by:
Hello, I am having some difficulty with the following C++: I have a declared a pointer to Foo like so: Foo *pFoo; Now, I have an API object that I try to use like so:
3
by: Beta What | last post by:
Hello, I have a question about casting a function pointer. Say I want to make a generic module (say some ADT implementation) that requires a function pointer from the 'actual/other modules'...
4
by: coder_lol | last post by:
Given the template class below, please help me understand the following code behavior? Array<int32ia(10); // Array that can contain 10 int32 ia = 1; // Array element 1 set to...
8
by: tharringtonan | last post by:
I am compiling the following code, main.cpp, as follows: gcc main.cpp I get the following compile error: main.cpp: In function `int main()': main.cpp:28: no matching function for call to...
8
by: vaib | last post by:
hi all , It really seems that C never ceases to amaze . All this time i've been doing C and i thought i was quite adept at it but i was wrong . So without wasting any more time , here's the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.