🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c
Article #4097

Re: Function-prototype scope: Why?

#4097
From: Clive D.W. Feather
Date: Fri, 22 Sep 1995 21:15
40 lines
2256 bytes
In article <43rqp8$6pc@rdsunx.crd.ge.com>,
Christopher R. Volpe <volpe@ausable.crd.ge.com> wrote:
>>	struct S;
>>	int k(struct S *);
> Right. The above code is legal, and the declared function can be used in a
> meaningful way. The point is that without f-p scope, you don't need the
> initial struct S declaration. It becomes implied.

[...]

> Of course, as I said before, f-p scope is useful for one thing: being able to
> have header files with comprehensible prototypes like:
>	int foobar(int window, float color);
> without corrupting the user's namespace with identifiers "window" and
> "color".

I'm not totally sure how this thread started, because I plonked halsaz
some time ago (how can *anyone* post about standards with such
deliberate non-standard spelling ?).

However, the logic behind function prototype scope is extremely simple:
* Prototypes are a good thing.
* Prototypes with dummy identifiers in can be better than without,
  because they're more self-documenting.
* These identifiers shouldn't pollute the file-scope namespace.
* Thus the parameters of a prototype should be in their own scope.

The Standard's authors prefered to have a simple concept of scope rather
than one full of special cases. So tags have the same (prototype) scope
as anything else within a prototype. This means you need to first
declare the tag outside the prototype. This is trivial, and makes it
clear that the tag used here is the same as the one used elsewhere in
file scope.

I happen to agree with this decision.

-- 
Clive D.W. Feather                       | If you lie to the compiler,
clive@demon.net        (work, preferred) | it will get its revenge.
clive@stdc.demon.co.uk (home)            |   - Henry Spencer
Technical Details
Message-ID: <DFBsED.2H1@stdc.demon.co.uk>
Path: arc1-ca.pugleaf.net!stdc.demon.co.uk!clive
References: <43cgmb$cec@news0.rain.rg.net> <43pdgk$b3i@rdsunx.crd.ge.com> <43qjdk$loj@caip.rutgers.edu> <43rqp8$6pc@rdsunx.crd.ge.com>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!stdc.demon.co.uk!clive
From: clive@stdc.demon.co.uk (Clive D.W. Feather)
Newsgroups: comp.std.c
Subject: Re: Function-prototype scope: Why?
Date: Fri, 22 Sep 1995 21:15:48 GMT
Organization: Demon Internet Limited (personal account)
Message-ID: <DFBsED.2H1@stdc.demon.co.uk>
References: <43cgmb$cec@news0.rain.rg.net> <43pdgk$b3i@rdsunx.crd.ge.com> <43qjdk$loj@caip.rutgers.edu> <43rqp8$6pc@rdsunx.crd.ge.com>
Reply-To: clive@demon.net
X-NNTP-Posting-Host: stdc.demon.co.uk