function arguments question (newbie)

Discussion in 'C Programming' started by Yoni Rabkin Katzenell, Jun 25, 2005.

  1. 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.

    --
    "Cut your own wood and it will warm you twice"
    Regards, Yoni Rabkin Katzenell
     
    Yoni Rabkin Katzenell, Jun 25, 2005
    #1
    1. Advertising

  2. Yoni Rabkin Katzenell

    Suman Guest

    Yoni Rabkin Katzenell wrote:
    > 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
    wrote a nice article about the same.

    And of course, search the group.

    Regards,
    Suman.
     
    Suman, Jun 25, 2005
    #2
    1. Advertising

  3. On Sat, 25 Jun 2005 11:42:43 +0300, Yoni Rabkin Katzenell wrote:

    >
    > 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
     
    Lawrence Kirby, Jun 25, 2005
    #3
  4. 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?

    --
    "Cut your own wood and it will warm you twice"
    Regards, Yoni Rabkin Katzenell
     
    Yoni Rabkin Katzenell, Jun 25, 2005
    #4
  5. Yoni Rabkin Katzenell

    Suman Guest

    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.
     
    Suman, Jun 25, 2005
    #5
    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. Neo
    Replies:
    10
    Views:
    666
    sushant
    Jan 20, 2005
  2. tutmann
    Replies:
    4
    Views:
    438
  3. jmborr
    Replies:
    1
    Views:
    421
    Stargaming
    Nov 3, 2007
  4. Replies:
    3
    Views:
    828
  5. Navaneeth
    Replies:
    4
    Views:
    553
    Kenny McCormack
    Nov 20, 2010
Loading...

Share This Page