Thread: Old style fuction declarations

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,664
    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.

  2. #2
    zach
    Guest
    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; 08-20-2019 at 09:05 AM.

  3. #3
    zach
    Guest
    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.

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