(Alan Curry) writes:
> In article <js5l0m$64l$>,
> Eric Sosman <> wrote:
>>On 6/23/2012 6:06 PM, Alan Curry wrote:
>>> In article <js32rk$siv$>,
>>> Eric Sosman <> wrote:
>>>> On 6/22/2012 6:40 PM, Alan Curry wrote:
>>>>> But is the compiler right for a real reason, or is it just a
>>>>> continuation of a historical accident? Why would you ever want
>>>>> this behavior?
>>>>
>>>> The Rationale sheds no light my tired old eyes can see. You
>>>> are welcome to read it for yourself. (Also, if you think the
>>>> normative text of the formal definition of the C language does not
>>>> qualify as "a real reason," well ...)
>>>
>>> The standard was supposed to codify existing practice. A real reason
>>> would have to come from before standardization. Was there a real
>>> reason for the existence of such a small, useless scope?
>>
>> Note that existing practice had no notion of prototypes at all,
>>so the issue of "prototype scope" simply didn't exist. (The ANSI
>>Standard invented other things new to the language, too: `void',
>>for example.)
>>
>> But once you've decided to declare a function with a prototype,
>>what scope should any identifiers in the prototype have? It seems
>>pretty clear you don't want them leaking outside, else
>>
>> void foo(char *p);
>> void bar(double *p);
>>
>>... wouldn't compile, because of the conflicting declarations of `p'.
>>I suggest that would have been untenable.
>
> Those names should simply be omitted, and it would be a good thing if they
> weren't allowed either. They serve no purpose and cause problems in header
> files when one header defines a macro that another header uses as an argument
> name in a prototype.
>
> We are allowed to use the intelligent comment markers /* */ in C, not just
> the dumb // to-end-of-line kind, so you can say
>
> void f(char * /*p*/, double * /*q*/);
>
> if the parameter names are meant to be documentation.
Personally, I like having names for parameters in function declarations,
though I'm not pleased that they're ignored. My own preference would be
to make the names mandatory, and to require them to match the names used
in the function's definition.
So neither of is 100% satisfied with the way C is defined. I don't know
of anyone who is.
(I disagree with your characterization of // comments as "dumb", but I
won't get into that.)
> Anyway, putting type names and variable names into a single category and
> calling them "identifiers" is a false generalization. It works at the
> technical level for the compiler implementor I guess, but besides that what's
> the reason for lumping them together and insisting that they behave the same?
> If you can't explain it without the word "identifier" then there is no
> reason, it's just a thought process that's being misled by a bit of escaped
> compiler-writer's jargon.
I'd say it's a perfectly valid generalization. They *are* both
identifiers, and they follow the same scope rules.
You advocate treating type names as a special case with different scope
rules than other identifiers. That's a valid preference, but not one
that I share -- and not one that's consistent with C as it's currently
defined.
>>> I don't think we'd be losing anything if those declarations were simply
>>> illegal. Declare your structs before your functions. They aren't variables.
>>
>> I'm glad the Standard didn't take your view. While I'll admit
>>that function-specific types are not all that common, I'll maintain
>>that they are extremely useful. Most often, there's an ad-hoc
>>table of some kind to assist a function in the performance of its
>>work: Maybe an association of states with their capitols, or ranges
>>of `x' where a rational function/Chebyshev approximation/continued
>>fraction is the preferred computation method. Whatever it is, if
>>it's specific to the operation of one function I see *no* reason to
>>inflict it on others.
>
> The same could be said for a function that's only called by one other
> function. Should we have nested functions then?
Many languages do have nested functions. What tends to make them
complicated is the need to define rules for accessing objects defined
in an outer function. I wouldn't strongly object to adding nested
functions to C (and gcc supports them as an extension), but I don't
think they're all that important; we've gotten along without them
for a very long time.
[...]
> Variable scopes make sense because the object named by the variable doesn't
> exist until the function is called. A type isn't an object.
Are you conflating scope and lifetime?
[...]
--
Keith Thompson (The_Other_Keith)
kst- <http://www.ghoti.net/~kst>
Will write code for food.
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"