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%

Thread: What is your view on having the protoype in headers

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Aug 2005
    Posts
    1,267
    I have a personal limt size for inline functions of 1 statement. If its more than 1 statement then I make it a normal function or class method. If it is only 1 statement then I normally inline it.

    Microsoft ATL/COM wizard is really netorious for putting lots of code in header files. I normally move that code to the implementation *.cpp file where most programmers I know would normally put it.

  2. #2
    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;}

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

  4. #4
    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;}

  5. #5
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    So you are inventing your own way of using headers and source files eh.

    Good luck with that.

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, 01: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