Does anyone have any opinions on not using prototypes unless necessary for functions declared “static”. Do you always put them at the top of your translation unit? I tend to but recently I’ve been thinking about why not rely on the ordering of the functions and in way you can limit some scope of where the function can be called from, potentially forcing yourself to think a little bit more about the scope of the function. I’m still on the side of doing the prototype, but I can see arguments aren’t completely baseless for the other side of the fence. I suppose this argument could also be continued on to #define and file scope variables.
Does anyone have any opinions on not using prototypes unless necessary for functions declared
Share
I follow the “define before use” rule myself wherever possible (thus my files always read from the bottom up). That way I don’t have to worry about keeping declarations and definitions in sync, at least within the same file.
To be pedantic, you’re talking about declarations, not prototypes; prototype refers to the syntax of a declaration/definition (i.e., declaring the number and types of parameters in the parameter list). To be clear, the following declaration and definition use prototype syntax:
whereas the following declaration and definition do not use prototype syntax:
Whether you define functions before use, or just declare before use and define later, always use prototype syntax.