Thread: Cant Understand the syntax

  1. #1
    Registered User
    Join Date
    Jun 2007
    Posts
    219

    Cant Understand the syntax

    I've seen the following in a .c File
    Code:
    static void MDString PROTO_LIST ((char *));
    static void MDTimeTrial PROTO_LIST ((void));
    static void MDTestSuite PROTO_LIST ((void));
    static void MDFile PROTO_LIST ((char *));
    static void MDFilter PROTO_LIST ((void));
    static void MDPrint PROTO_LIST ((unsigned char [16]));
    But cant understand what does it mean.
    PROTO_LIST is a function or a struct name.
    But still the syntax is complex to me I cant understand it.
    anyone plese clearify.

  2. #2
    Registered User
    Join Date
    Sep 2007
    Posts
    1,012
    Back in the bad old days, C didn't have prototypes, so function declarations looked like:
    Code:
    char *f();
    instead of
    Code:
    char *f(const char *);
    Or whatever the parameters were. The point is that K&R C (the older dialect) had no way of listing the types of parameters to a function. As you are probably aware, having the types is extremely useful. So people wanted to use prototypes, but also needed to be compatible with older compilers.

    Thus you get a macro like PROTO_LIST. Its definition probably looks something like:
    Code:
    #if __STDC__
    #define PROTO_LIST(p) p
    #else
    #define PROTO_LIST(p) ()
    #endif
    So if __STDC__ is true (that is, we're on a standards-compliant implementation), the prototype is used. If it's false, no prototype is used. Compatible with both ancient and modern compilers.

  3. #3
    Registered User
    Join Date
    Jun 2007
    Posts
    219
    Haaaaaaaaa I got a Brand knew drop of historical Knowledge.
    C didn't have prototypes
    Then how did programmers pass the arguments ?

  4. #4
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,210
    You just passed them. We're talking prototypes, not types.

  5. #5
    Registered User
    Join Date
    Jun 2007
    Posts
    219
    I meant if Its char *f();
    then how can one pass argument to f() ?

  6. #6
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    You could pass anything you liked (which was part of the problem, and why tools like lint existed).

    f(123);
    f("hello world");
    would silently compile on very old compilers.
    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.

  7. #7
    Registered User
    Join Date
    Jun 2007
    Posts
    219
    so how the function body get that argument.
    e.g. now a days we do f(int x)
    so if f(123) is used x = 123 but if its f() then who will hold that 123 ??

  8. #8
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,210
    You would define a function in some manner like this:

    Code:
    int dosomething(x)
    int x;
    {
        printf("x = %d\n", x);
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. more then 100errors in header
    By hallo007 in forum Windows Programming
    Replies: 20
    Last Post: 05-13-2007, 08:26 AM
  2. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 05:45 PM
  3. Using VC Toolkit 2003
    By Noobwaker in forum Windows Programming
    Replies: 8
    Last Post: 03-13-2006, 07:33 AM
  4. Connecting to a mysql server and querying problem
    By Diod in forum C++ Programming
    Replies: 8
    Last Post: 02-13-2006, 10:33 AM
  5. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM