| TIP: Click on subject to list as thread! | ANSI |
| echo: | |
|---|---|
| to: | |
| from: | |
| date: | |
| subject: | Sub |
Hello Darin. 22 Jul 98 18:31, Darin McBride wrote to Roger Scudder: RS>> You should place declerations (prototypes) for all functions at the RS>> top of the source file. This is optional in C and required in C++. RS>> The correct way is to place prototypes in a header file and include RS>> the header in all .c files that use one, some, or all of the functions. DM> Required in C++? No - I almost never do this. I only use prototypes in DM> C++ when the function is part of a class or in another module. Otherwise I DM> (almost) always define functions before they're used. I have read so much about how one should use prototypes in C++ due to strong type checking that somewhere along the way I must have assumed it was required. ( Please bear with me... I'm still learning C++... ) I'm sure prototypes are required in a program that uses strict top down design. I don't want to get into C++ here, but when you say you use prototypes when the function is a a part of a class... by part of I assume you me a member of... isn't it correct to declare a class in the .h file and in doing that all member functions are always declared in the .h file? Then any functions that are not implemented inline are implemented in the .cpp file? So from your statement above, you only use prototypes when you must due to language requirements? I think that is a mistake. Prototypes are a good thing that can make the job of the next person to maintain your program easier. I would be glad to continue this in the C++ Echo if you like... DM> If a function needs to be visible before it is defined, prototype it in the DM> source file (.c, .cc, .C, .cpp, whatever). If a function needs to be DM> visible in other modules, prototype it in the header file. (If a function DM> needs to be visible to other DLLs/EXEs, export it...) Simple rules... :-) That is ok for small programs with a small number of modules. In larger programs placing prototypes in the source files only makes things more difficult for the next programmer who has to modify the program. It's sloppy to have a program with say 75 - 100 or more modules where some prototypes are in the .c modules are others are not. With small programs it doesn't matter as much, but I like to stay consistant so I always use header files in any formal program. DM> This also means that my main is always at the bottom of its module... Which is the opposite of top down design. I'm not trying to say there is anything wrong with doing it your way. I know that alot of programmers do. In some more obscure languages that don't have prototyping you must do it that way. With C I think it is a question of style and as such we could argue forever about what is best. I like to follow a style that places main at the top of a module that is named to reflect it's place in the whole. Related functions are placed in modules that are named to reflect their place in the whole. All declerations are placed in header files. I find that this makes programs easier to maintain. Roger --- Msged/2 4.10* Origin: [A Mail Only Node], Upper Darby, PA, USA (1:273/404{at}fidonet) SEEN-BY: 396/1 622/419 632/371 633/260 267 270 371 634/397 635/506 728 SEEN-BY: 639/252 670/213 218 @PATH: 273/404 416 2604/104 270/101 396/1 633/260 635/506 728 633/267 |
|
| SOURCE: echomail via fidonet.ozzmosis.com | |
Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.