View Poll Results: Should people include prototypes in headers?

Voters
15. You may not vote on this poll
  • Yeah

    12 80.00%
  • No

    3 20.00%
  • No but I do it anyway

    0 0%

What is your view on having the protoype in headers

This is a discussion on What is your view on having the protoype in headers within the C++ Programming forums, part of the General Programming Boards category; I keep hearing it's wrong, but I do it anyway. Between me and myself, I'm used to placing functions/classes in ...

  1. #16
    Registered User
    Join Date
    Mar 2006
    Posts
    725
    I keep hearing it's wrong, but I do it anyway. Between me and myself, I'm used to placing functions/classes in header files and "executable" code (eg. globals, main()) in source files.

    Yes, I keep hearing it's wrong...
    Code:
    #include <stdio.h>
    
    void J(char*a){int f,i=0,c='1';for(;a[i]!='0';++i)if(i==81){
    puts(a);return;}for(;c<='9';++c){for(f=0;f<9;++f)if(a[i-i%27+i%9
    /3*3+f/3*9+f%3]==c||a[i%9+f*9]==c||a[i-i%9+f]==c)goto e;a[i]=c;J(a);a[i]
    ='0';e:;}}int main(int c,char**v){int t=0;if(c>1){for(;v[1][
    t];++t);if(t==81){J(v[1]);return 0;}}puts("sudoku [0-9]{81}");return 1;}

  2. #17
    Registered User
    Join Date
    Aug 2005
    Posts
    1,267
    Quote Originally Posted by jafet
    I keep hearing it's wrong, but I do it anyway. Between me and myself, I'm used to placing functions/classes in header files and "executable" code (eg. globals, main()) in source files.

    Yes, I keep hearing it's wrong...
    I think you mean you put function prototypes in header files. If you put the whole function in the headers the linker would complain about duplicate symbol declarations if you include that header in two or more *.c or *.cpp files.

    And I don't think anyone has said that is wrong. That's the way it is supposed to be done. That's what God created header files for

  3. #18
    Registered User
    Join Date
    Mar 2006
    Posts
    725
    Nope, I meant what I meant. I put entire CLASSES, function DEFINITIONS and the like into .h files. .cpp files houses main(), globals, code, small specialized functions etc. I do preprocessor checking on the header files so nothing goes wrong. AND I rarely go to the trouble to write function declarations; to me they're a waste of space. Call it habit
    Code:
    #include <stdio.h>
    
    void J(char*a){int f,i=0,c='1';for(;a[i]!='0';++i)if(i==81){
    puts(a);return;}for(;c<='9';++c){for(f=0;f<9;++f)if(a[i-i%27+i%9
    /3*3+f/3*9+f%3]==c||a[i%9+f*9]==c||a[i-i%9+f]==c)goto e;a[i]=c;J(a);a[i]
    ='0';e:;}}int main(int c,char**v){int t=0;if(c>1){for(;v[1][
    t];++t);if(t==81){J(v[1]);return 0;}}puts("sudoku [0-9]{81}");return 1;}

  4. #19
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,590
    So you are inventing your own way of using headers and source files eh.

    Good luck with that.

  5. #20
    semi-colon generator ChaosEngine's Avatar
    Join Date
    Sep 2005
    Location
    Chch, NZ
    Posts
    597
    Quote Originally Posted by swgh
    Inline can speed up a program, but requires more typing
    how does it require more typing?

    Code:
    // x.h
    
    class X
    {
    public:
        // note that the "inline" here is not really necessary
        inline int someFunc() { return 5; }
    };
    versus
    Code:
    // x.h
    
    class X
    {
    public:
        int someFunc();
    };
    
    // x.cpp
    
    int X::someFunc()
    {
        return 5;
    }
    seems about the same to me. if anything, the inline is shorter.

    BTW inlining can also slow your code down too! it can result in a bigger executable, which can cause page misses, etc.

    have a read of this FAQ
    "I saw a sign that said 'Drink Canada Dry', so I started"
    -- Brendan Behan

    Free Compiler: Visual C++ 2005 Express
    If you program in C++, you need Boost. You should also know how to use the Standard Library (STL). Want to make games? After reading this, I don't like WxWidgets anymore. Want to add some scripting to your App?

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Tree View Control flickering
    By cfriend in forum Windows Programming
    Replies: 1
    Last Post: 09-13-2004, 09:25 AM
  2. Tree View control not appearing
    By Garfield in forum Windows Programming
    Replies: 1
    Last Post: 03-07-2004, 12:47 PM
  3. Headers that use each other
    By nickname_changed in forum C++ Programming
    Replies: 7
    Last Post: 10-03-2003, 04:25 AM
  4. Set View Position in CEditView :: MFC
    By kuphryn in forum Windows Programming
    Replies: 1
    Last Post: 05-21-2002, 09:27 PM
  5. Determining Active View :: MFC
    By kuphryn in forum Windows Programming
    Replies: 0
    Last Post: 04-25-2002, 07:34 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21