Which function header do you prefer?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • istillshine@gmail.com

    Which function header do you prefer?

    int foo(x, y, z)
    double *x;
    int y;
    double z;
    {
    /* do something */
    }

    or

    int foo(double *x, int y, double z)
    {
    /* do something */
    }


    I notice the first one appeared in 1978's The C Programming Language
    book.
    The second edition of the book adopted the second one. The first one
    seem more
    readable when there are many arguments.
  • Hallvard B Furuseth

    #2
    Re: Which function header do you prefer?

    istillshine@gma il.com writes:
    int foo(x, y, z)
    double *x;
    int y;
    double z;
    {
    /* do something */
    }
    >
    or
    >
    int foo(double *x, int y, double z)
    {
    /* do something */
    }
    >
    >
    I notice the first one appeared in 1978's The C Programming Language
    book.
    The 2nd form is called a prototype, and makes the compiler do type
    checking on the arguments and convert them to the types of the parameter
    if needed. E.g.
    int foo(x) long x; {...}
    ... foo(3); ...
    is wrong, it should have been foo(3L). But foo(3) is correct if
    you used a prototype: int foo(long x);'.
    The second edition of the book adopted the second one. The first one
    seem more readable when there are many arguments.
    Then write the 2nd like this:
    int foo(
    double *x,
    int y,
    double z)

    --
    Hallvard

    Comment

    Working...