home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!stanford.edu!agate!dog.ee.lbl.gov!horse.ee.lbl.gov!torek
- From: torek@horse.ee.lbl.gov (Chris Torek)
- Newsgroups: comp.lang.c
- Subject: Re: question about duplicate declarations
- Date: 19 Nov 1992 19:00:19 GMT
- Organization: Lawrence Berkeley Laboratory, Berkeley
- Lines: 53
- Message-ID: <27543@dog.ee.lbl.gov>
- References: <1992Oct17.104808.29033@mccc.edu> <1849@lysator.liu.se> <26961@dog.ee.lbl.gov> <1992Oct26.172233.2045@mccc.edu> <26987@dog.ee.lbl.gov> <720329596@sheol.UUCP> <2R28E4L@math.fu-berlin.de>
- Reply-To: torek@horse.ee.lbl.gov (Chris Torek)
- NNTP-Posting-Host: 128.3.112.15
-
- In article <2R28E4L@math.fu-berlin.de> rene@hamel.uucp (Rene Mueller) writes:
- >In a function there couldn't be a[nother] fuction definition..
-
- True enough. Function *declarations* are, however, permitted.
-
- >So code like
- >typ f1(paramlist)
- >{
- >typ f2(paramlist);
- > .
- > .
- > .
- >}
- >Shouldn't be in ANY programm...
-
- ANSI C allows code of the above form. The declaration for f2()
- gives it the corresponding type, and the identifier goes out of scope
- at the closing brace.
-
- (Stylistically, I happen to agree; function declarations with block
- scope provide nothing that the same declaration with file or global
- scope would give, except the chance to make a mistake.)
-
- >and things like
- >typ f();
- >means that f is a function with NO parameter returning a value from type typ
-
- No. In ANSI C, an empty parameter list means `the number and types of
- the parameters are unspecified'. This imposes a separate set of type
- compatibility rules. Note that this differs from C++, where `int f()'
- means the same as ANSI C's `int f(void)'.
-
- >... so typ f(paramlist) is a redeclaration with WRONG type
-
- In ANSI C, the redeclaration is compatible (I called it `benign') if
- and only if the return type is compatible, the parameters in the
- `paramlist' all have `wide' types, and the actual function does not
- take variable arguments.
-
- An incompatible (`malignant') redeclaration is apparently permitted
- under ANSI C. If you call a function whose current in-scope
- declaration is incompatible with the actual type of the actual
- function, the result is undefined. A future version of the standard
- will probably outlaw malignant redeclarations (note, this is sheer
- speculation on my part, and it does not completely eliminate the
- problem, only one aspect of it).
-
- Note that any compiler can issue warnings at any time, so a good compiler
- can already warn about malignant redeclarations. A diagnostic is not
- required, but no diagnostic is ever forbidden.
- --
- In-Real-Life: Chris Torek, Lawrence Berkeley Lab CSE/EE (+1 510 486 5427)
- Berkeley, CA Domain: torek@ee.lbl.gov
-