Thread: differently or not?

  1. #1
    Registered User
    Join Date
    Jan 2009
    Posts
    77

    differently or not?

    hello,
    tell me please, if two different ways to using struct or not?
    funclion called in head source file like this...
    Code:
    static void func(struct a *);
    next I need use it.
    which's way would be most good?
    Code:
    //1
     func(struct a *p){
    ..
    }
    //2
     func(p)
     struct  a *p;
    {
    ..
    }

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    It looks like you are talking about parameter declaration style, and consequently the former is better because it is more commonly used nowadays, and ensures that the parameter type is made known.
    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

  3. #3
    Registered User
    Join Date
    Oct 2008
    Location
    TX
    Posts
    2,059
    The second one is old, pre-ANSI style declarations.

  4. #4
    HelpingYouHelpUsHelpUsAll
    Join Date
    Dec 2007
    Location
    In your nightmares
    Posts
    223
    Even better to call like this with the return type specified, so it is clear which type the function returns w/o consulting the prototype:
    Code:
    void func(struct a *p) { ... }
    //2
    func(p)
    struct a *p;
    {
    This at first looks as if p is being redeclared (which it would be if struct a *p was after the {).
    The second one is old, pre-ANSI style declarations.
    I never knew that this was ever a valid declaration.
    long time no C; //seige
    You miss 100% of the people you don't C;
    Code:
    if (language != LANG_C && language != LANG_CPP)
        drown(language);

  5. #5
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by P4R4N01D
    I never knew that this was ever a valid declaration.
    It is still valid, though I do not think it has been deprecated/obsoleted despite being practically obsolete.
    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

  6. #6
    Registered User
    Join Date
    Oct 2008
    Location
    TX
    Posts
    2,059
    Quote Originally Posted by P4R4N01D View Post
    I never knew that this was ever a valid declaration.
    AFAIK that syntax is supported only by legacy compilers not the modern ones. Some modern ones have options that morph them into legacy compilers but those are few and far between.
    Last edited by itCbitC; 02-25-2009 at 01:59 AM.

  7. #7
    HelpingYouHelpUsHelpUsAll
    Join Date
    Dec 2007
    Location
    In your nightmares
    Posts
    223
    Ah, thanks. Still should avoid using it where possible though -> Maximise portibility
    long time no C; //seige
    You miss 100% of the people you don't C;
    Code:
    if (language != LANG_C && language != LANG_CPP)
        drown(language);

  8. #8
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by itCbitC
    AFAIK that syntax is supported only by legacy compilers not the modern ones.
    I do not think so, since that syntax remains part of even the 1999 edition of the C standard.

    EDIT:
    Ah, but I have found where the standard does say that the feature is obsolescent - section 6.1.1.7 of C99: "The use of function definitions with separate parameter identifier and declaration lists (not prototype-format parameter type and identifier declarators) is an obsolescent feature." However, an obsolescent feature is one that has been considered for withdrawal in future versions of the standard.
    Last edited by laserlight; 02-25-2009 at 02:04 AM.
    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

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Why does it run differently?
    By Leftos in forum C Programming
    Replies: 26
    Last Post: 12-12-2007, 06:03 AM
  2. Would anyone do this differently?
    By misplaced in forum C++ Programming
    Replies: 8
    Last Post: 09-29-2004, 10:59 AM
  3. Does windows XP handle color depth differently than ME or 2000?
    By Stormkoopa in forum Windows Programming
    Replies: 1
    Last Post: 11-05-2002, 06:10 AM
  4. Images displayed differently in Opera????
    By Imperito in forum A Brief History of Cprogramming.com
    Replies: 6
    Last Post: 08-26-2002, 02:50 PM
  5. thinking differently doesn't pay off until you are dead
    By Aran in forum A Brief History of Cprogramming.com
    Replies: 9
    Last Post: 01-21-2002, 01:43 AM