Article View: comp.std.c
Article #4012Re: Function-prototype scope: Why?
From: J. Kanze
Date: Mon, 18 Sep 1995 08:14
Date: Mon, 18 Sep 1995 08:14
36 lines
2585 bytes
2585 bytes
Christopher R. Volpe (volpe@bart.crd.ge.com) wrote:
|> First of all, old K&R C syntax, with no prototypes whatsoever, was enough for
|> compilers to generate correct code, presuming the programmer passed the
|> expected type. Prototypes enabled the compiler to do some consistency checking
|> and implicit conversions, not solve any inherent inability to generate correct
|> code.
|> Secondly, even if prototypes in general were necessary for correct code
|> generation, and even if all struct pointers didn't "smell alike", it still
|> doesn't explain why function-prototype scope is needed. Even if it were
|> necessary that pointer-type parameters be pointers to complete types, it is
|> still possible (in fact, it's pretty much mandatory if you want to actually
|> *use* the function) to declare the complete structure type before the
|> prototype.
|> I suspect that function-prototype scope exists so that prototypes can include
|> the parameter-name identifiers (for purposes of self-documentation) without
|> corrupting the file- or block-scope namespace in which the prototype
|> occurred. I also suspect that adding rules to disallow only certain
|> declarations (i.e. struct declarations) in only certain scopes (i.e.
|> function-prototype scope) just complicated the rules more than it was worth.
I *think* that the rationale for disallowing defining new types in
function prototypes is that there is no way to use such types. In C++
(which uses name equivalence), there is in fact no way to even call the
function (since the function must be called with a type whose scope ends
at the end of the function prototype). In C, if I'm not mistaken, it
should be possible to declare an exactly equivalent type outside the
function prototype, and use it, although I imagine that this would be
very error prone.
--
James Kanze (+33) 88 14 49 00 email: kanze@gabi-soft.fr
GABI Software, Sarl., 8 rue des Francs Bourgeois, 67000 Strasbourg, France
Conseils en informatique industrielle--
--Beratung in industrieller Datenverarbeitung
Technical Details
Message-ID:
<43j9oo$62d@gabi.gabi-soft.fr>Path:
arc1-ca.pugleaf.net!gabi-soft.fr!not-for-mailReferences:
<43cgmb$cec@news0.rain.rg.net> <43er80$458@caip.rutgers.edu> <43i723$j90@rdsunx.crd.ge.com>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!gabi-soft.fr!not-for-mail From: kanze@gabi-soft.fr (J. Kanze) Newsgroups: comp.std.c Subject: Re: Function-prototype scope: Why? Date: 18 Sep 1995 10:14:16 +0200 Organization: GABI Software, Sarl. Distribution: world Message-ID: <43j9oo$62d@gabi.gabi-soft.fr> References: <43cgmb$cec@news0.rain.rg.net> <43er80$458@caip.rutgers.edu> <43i723$j90@rdsunx.crd.ge.com> NNTP-Posting-Host: gabi.gabi-soft.fr X-Newsreader: TIN [version 1.2 PL2]