Variable/parameter declaration inconsistency

A

August Karlstrom

Hi

What's the cause of the inconsistency between variable and parameter
declarations in C? What's wrong with e.g.

void f(int a, b; char c);


August
 
M

Michael Mair

August said:
Hi

What's the cause of the inconsistency between variable and parameter
declarations in C? What's wrong with e.g.

void f(int a, b; char c);

This question may be better asked in comp.std.c, I guess.

I do not see the lack of such a form of declaration as
a disadvantage, however.
I would not gain anything most of the time; in addition,
I only use the
T a, b;
form of declaration for auxiliary variables such as loop
counters and prefer "one declaration/line" the rest of the
time. By this sign, I would like a semicolon after the
last parameter declaration which would make me type more
rather than less most of the time...

Cheers
Michael
 
K

Keith Thompson

August Karlstrom said:
What's the cause of the inconsistency between variable and parameter
declarations in C? What's wrong with e.g.

void f(int a, b; char c);

In an old-style declaration, that would look like:

f(a, b, c);

or, in the function definition:

f(a, b, c);
int a, b;
char c;
{
...
}

With prototypes, the parameter declarations are still separated by
commas, rather than the semicolons that are used to terminate ordinary
declarations. If the inventors of prototypes had chosen to use
semicolons rather than commas:

void f(int a; int b; char c); /* optional semicolon after c? */

then it would make sense to allow commas as well:

void f(int a, b; char c);

But it wasn't done that way, and I doubt that it could be changed
without breaking existing code, or at least causing confusion in some
cases.

Using semicolons rather than commas in prototypes might have been more
consistent, but I don't think it's worth fixing. I almost always
prefer to have one item per declaration anyway.
 
E

Eric Sosman

Keith Thompson wrote On 12/19/05 18:32,:
In an old-style declaration, that would look like:

f(a, b, c);

No; the parameter list in an old-style declaration
would be merely `()'.
 
K

Keith Thompson

Eric Sosman said:
Keith Thompson wrote On 12/19/05 18:32,:

No; the parameter list in an old-style declaration
would be merely `()'.

I thought you could give the parameter names in a declaration. But
now that I think about it, that could conflict (or at least be
confusing) with a modern prototype that specifies the types but not
the names, such as "void f(int, int, char);". I don't have my K&R1
handy; I'll check it when I do. But you're probably right.
 
E

Eric Sosman

Keith Thompson wrote On 12/20/05 14:45,:
I thought you could give the parameter names in a declaration. But
now that I think about it, that could conflict (or at least be
confusing) with a modern prototype that specifies the types but not
the names, such as "void f(int, int, char);". I don't have my K&R1
handy; I'll check it when I do. But you're probably right.

Pages 70 and 194.

(Don't feel bad. Just a few days ago I made a similar
blunder on this same newsgroup, having not used old-style
functions since the long-ago days when my eyebrow-to-hairline
measurement didn't require a yardstick. The modern style is
so superior in every way -- regardless of its punctuation --
that there's little reason to maintain familiarity with the
old. I still recognize it when I bump into it, but the next
thing I do is replace it with the modern equivalent. This
diminishes the bumping frequency, and the old ways recede ...)
 
A

August Karlstrom

Thanks for all replies. Anyway, the more I think about it the more
convinced I get that using only comma to separate formal parameters
(though slightly inconsistent) is the way to go.


August
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,172
Messages
2,570,934
Members
47,473
Latest member
ChristelPe

Latest Threads

Top