jwp@larry.UUCP (Jeffrey W Percival) (01/21/89)
At the risk of starting some kind of style war, let me raise a question. I've always been a bit bothered by this aspect of C: Subroutines and return types must be declared in the calling routine, unless if it returns an integer, and then you can just forget about it. I mean, either declarations are important or they're not, right? Now, before you call me a ninny let me point out that I know why other types must be declared (stacks and all that), and because only one type is excused, the compiler is not really at a loss to know what's going on. Some of the scope rules also seem a bit loose. Probably for historical reasons, I'll wager. The question is, do "good" programmers typically take advantage of these concessions, or do they assiduously declare their integer functions and keep their "scopes" as collapsed as possible? The second part of the question concerns lint. I wish lint had a "strict" mode, where it would not assume such things. For clarity for future browsers, if nothing else, it would be nice to be told that a declaration is missing, even if the compiler can figure it out. Does anyone have a lint-like tool that does not pander to these "forgiving" scope rules and default declarations? -- Jeff Percival (jwp@larry.sal.wisc.edu)
gwyn@smoke.BRL.MIL (Doug Gwyn ) (01/21/89)
In article <501@larry.UUCP> jwp@larry.UUCP (Jeffrey W Percival) writes: >The question is, do "good" programmers typically take advantage of these >concessions, or do they assiduously declare their integer functions and >keep their "scopes" as collapsed as possible? Both approaches are considered proper, since both remain within the official definition of the language. Personally, I declare all externs (not done by headers) just after the inclusion of headers near the start of the source file. Occasionally this catches a bug that would otherwise be hard to find. More importantly, it documents the interdependency between modules. Usually, when I need some variables with extremely localized scope and a function call doesn't seem appropriate, I'll declare the variables in a local block. Besides protecting against bugs, this also helps some compilers do a better job of register allocation. >Does anyone have a lint-like tool that does not pander to these >"forgiving" scope rules and default declarations? There are many variants of "lint", but I don't recall hearing of one that would squawk about legal use of implied function declaration.