Thread: Strange syntax

  1. #1
    Registered User
    Join Date
    Mar 2009
    Posts
    399

    Strange syntax

    Why would you ever define a function like this:

    Code:
    void foo(bar)
        int bar;
    {
        /* Do something with bar. */
        return;
    }
    I was reading through some open source project's code when I noticed that a lot of functions looked like that, and I don't think I've ever seen that construct in any book or tutorial.

  2. #2
    Registered User
    Join Date
    Aug 2006
    Posts
    100
    That is old, old C code. 20 or more years ago, you had to declare passed function parameters just before the opening brace of the function.

  3. #3
    DESTINY BEN10's Avatar
    Join Date
    Jul 2008
    Location
    in front of my computer
    Posts
    804
    Quote Originally Posted by Memloop View Post
    Why would you ever define a function like this:

    Code:
    void foo(bar)
        int bar;
    {
        /* Do something with bar. */
        return;
    }
    I was reading through some open source project's code when I noticed that a lot of functions looked like that, and I don't think I've ever seen that construct in any book or tutorial.
    This is called K&R style function definitions. K&R-style function definitions have been obsolete since 1989.
    HOPE YOU UNDERSTAND.......

    By associating with wise people you will become wise yourself
    It's fine to celebrate success but it is more important to heed the lessons of failure
    We've got to put a lot of money into changing behavior


    PC specifications- 512MB RAM, Windows XP sp3, 2.79 GHz pentium D.
    IDE- Microsoft Visual Studio 2008 Express Edition

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. what am I missing? (Program won't compile)
    By steals10304 in forum C Programming
    Replies: 3
    Last Post: 08-25-2009, 03:01 PM
  2. more then 100errors in header
    By hallo007 in forum Windows Programming
    Replies: 20
    Last Post: 05-13-2007, 08:26 AM
  3. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 05:45 PM
  4. Using VC Toolkit 2003
    By Noobwaker in forum Windows Programming
    Replies: 8
    Last Post: 03-13-2006, 07:33 AM
  5. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM