function arguments question (newbie)

  • Thread starter Yoni Rabkin Katzenell
  • Start date
Y

Yoni Rabkin Katzenell

Hello,

The following useless code seems to compile and run, but I'm not sure
why. I turned on all the compiler warning flags, but it remains silent.

[Start code]

1 #include <stdlib.h>
2 #include <stdio.h>
3
4 int main (argc, argv)
5 int argc; char *argv[];
6 {
7 (void) printf("%d\n", argc);
8 return(EXIT_SUCCESS);
9 }

[End code]

My question is concerning the style of declaring the argument types
between the function and the block of code as in line 5. This as opposed
to what I'm used to seeing:

....some-code...
int main (int argc, char *argv[])
{
....more-code...

What style is that? Is it standard C?

Of course I'm not asking specifically about 'argc' and 'argv', but about
that form of declaration for a function's arguments.

Thank you in advance.
 
S

Suman

Yoni said:
Hello,

The following useless code seems to compile and run, but I'm not sure
why. I turned on all the compiler warning flags, but it remains silent.

[Start code]

1 #include <stdlib.h>
2 #include <stdio.h>
3
4 int main (argc, argv)
5 int argc; char *argv[];
6 {
7 (void) printf("%d\n", argc);
8 return(EXIT_SUCCESS);
9 }

[End code]

My question is concerning the style of declaring the argument types
between the function and the block of code as in line 5. This as opposed
to what I'm used to seeing:

...some-code...
int main (int argc, char *argv[])
{
...more-code...

What style is that? Is it standard C?

Of course I'm not asking specifically about 'argc' and 'argv', but about
that form of declaration for a function's arguments.
You can read this:
http://groups.google.co.in/group/comp.lang.c/browse_frm/
thread/3924642d9c5d38ea/eb9f785b9abbd97b?hl=en#eb9f785b9abbd97b
(e-mail address removed) wrote a nice article about the same.

And of course, search the group.

Regards,
Suman.
 
L

Lawrence Kirby

Hello,

The following useless code seems to compile and run, but I'm not sure
why. I turned on all the compiler warning flags, but it remains silent.

[Start code]

1 #include <stdlib.h>
2 #include <stdio.h>
3
4 int main (argc, argv)
5 int argc; char *argv[];
6 {

This is the old form of function definition, known as non-prototype or K&R
form.
7 (void) printf("%d\n", argc);
8 return(EXIT_SUCCESS);
9 }

[End code]

My question is concerning the style of declaring the argument types
between the function and the block of code as in line 5. This as opposed
to what I'm used to seeing:

...some-code...
int main (int argc, char *argv[])
{

This is the newer prototype form forst used in C++ and adopted in standard
C in 1989.

C still supports both forms but you should always use the prototype form
unless you have to support a VERY old compiler. The prototype form
requires extra type checking from the compiler.

Lawrence
 
Y

Yoni Rabkin Katzenell

Thank you.

Sorry but I did not know exactly what to google for, since I could not
guess what the form is called.

Admittedly I posted the question rather quickly after it came to my
mind. After a short skim through the c.l.c FAQ and my ANSI K&R.

I understand that the reason I did not find it in my ANSI K&R is that it
was standardized away before the book was published? Or maybe I should
look harder?
 
S

Suman

Yoni Rabkin Katzenell wrote:
....
I understand that the reason I did not find it in my ANSI K&R is that it
was standardized away before the book was published? Or maybe I should
look harder?

I do have a pretty old book abut creating window-ed UI in C that used
such form. I do not though know/remember if there was/is a version of
K&R
which used that syntax. Most probably it(*such a book*) did exist in
the pre-ANSI days.

Regrads,
Suman.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,276
Latest member
Sawatmakal

Latest Threads

Top