Thread: Old style fuction declarations

  1. #1
    Registered User
    Join Date
    Aug 2019
    Location
    Groningen Netherlands
    Posts
    105

    Old style fuction declarations

    When I look up on the Net, what old and new style function declarations look like, I get a whole lot gibberdejab. Please give me a simple example of an old, and a new style function declaration, showing the difference, so I might learn what one should and shouldn't do. Thank you, Zach K.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    37,380
    Quote Originally Posted by c99
    6.11.4 Function declarators
    The use of function declarators with empty parentheses (not prototype-format parameter
    type declarators) is an obsolescent feature.

    6.11.5 Function definitions
    The use of function definitions with separate parameter identifier and declaration lists
    (not prototype-format parameter type and identifier declarators) is an obsolescent feature.
    Code:
    /* Old style function declarator */
    void foo();
    
    /* Old style function definition */
    void foo()
      int a;
    {
      /* do stuff */
    }
    In particular, there were NO checks on calling foo().
    You could do
    foo();
    foo(123);
    foo("I'm a banana");

    without any compile time consequence.




    As the standard says, these are obsolete syntax.

    You should be doing
    Code:
    void foo(int a);
    
    void foo(int a) {
      /* do stuff */
    }
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Aug 2019
    Location
    Groningen Netherlands
    Posts
    105
    Being Dutch I have a continuous problem with IT explanations written in English.

    At the top of a program, right underneath the "includes", are they "declarations"?
    The first line of a function, is that the definition?
    Then what is old style and what is new at the top of the program = declarations I presume?
    Please a simple answer.
    Last edited by zach; 4 Weeks Ago at 09:05 AM.

  4. #4
    Registered User
    Join Date
    Aug 2019
    Location
    Groningen Netherlands
    Posts
    105
    A complete example with *only* but *all* the relevant lines often is *much* more informative than jargon text of which the reader might not understand all the words. This is my many years of teaching experience. I find many explanations on the Net totally bewildering.

  5. #5
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    37,380
    Forget about the old style, just use a function prototype and a function definition.

    The old style has some odd terminology, which you're not understanding, and you don't need to worry about.

    And no, writing it in a "dumbed down" colloquial English will only serve to confuse further by overloading different specific meanings onto one general term.


    Code:
    // This is a prototype, it has the parameter types already listed.
    void foo(int a);
     
    // This is a definition, it matches the prototype.
    void foo(int a) {
      /* do stuff */
    }
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  6. #6
    Registered User
    Join Date
    Aug 2019
    Location
    Groningen Netherlands
    Posts
    105
    "And no, writing it in a "dumbed down" colloquial English will only serve to confuse further by overloading different specific meanings onto one general term."

    I am not talking about dunned down English!!

    I am saying *stick to the principle involved* and down dress it up wit a lot of airy fairy talk. I am speaking in general. Not to you personally. You are a great help all the time.

  7. #7
    Registered User
    Join Date
    Aug 2019
    Posts
    35
    I'm still reading through this but I really like the way many things are explained in it. Might be helpful to you...

    C++ Core Guidelines

  8. #8
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    27,025
    Zeus_, that's for C++. This is the C programming forum.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  9. #9
    Registered User
    Join Date
    Apr 2017
    Location
    Iran
    Posts
    91
    Quote Originally Posted by zach View Post
    When I look up on the Net, what old and new style function declarations look like, I get a whole lot gibberdejab. Please give me a simple example of an old, and a new style function declaration, showing the difference, so I might learn what one should and shouldn't do. Thank you, Zach K.
    How about you read K&R . Note that first chapter is different from other chapters. I suppose both function declarations are discussed in the book.

  10. #10
    Registered User
    Join Date
    Aug 2019
    Posts
    35
    Oh yeah, sorry! I forgot that I switched between the programming boards

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 11
    Last Post: 11-23-2015, 02:55 PM
  2. about fuction!
    By llinocoe in forum C Programming
    Replies: 6
    Last Post: 09-23-2008, 08:50 AM
  3. c-style string vs. c++-style strings
    By Mbrio in forum C++ Programming
    Replies: 3
    Last Post: 02-10-2002, 12:26 PM
  4. Need Help With this Fuction
    By golfinguy4 in forum Windows Programming
    Replies: 2
    Last Post: 01-23-2002, 03:00 PM
  5. how do I extract a style from a DWORD style
    By zMan in forum Windows Programming
    Replies: 1
    Last Post: 01-17-2002, 10:09 AM

Tags for this Thread