By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,804 Members | 1,634 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,804 IT Pros & Developers. It's quick & easy.

Variable/parameter declaration inconsistency

P: n/a
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

--
I am the "ILOVEGNU" signature virus. Just copy me to your
signature. This email was infected under the terms of the GNU
General Public License.
Dec 19 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
August Karlstrom wrote:
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
--
E-Mail: Mine is an /at/ gmx /dot/ de address.
Dec 19 '05 #2

P: n/a
August Karlstrom <fu********@comhem.se> writes:
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.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Dec 19 '05 #3

P: n/a


Keith Thompson wrote On 12/19/05 18:32,:
August Karlstrom <fu********@comhem.se> writes:
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);


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

--
Er*********@sun.com

Dec 20 '05 #4

P: n/a
Eric Sosman <er*********@sun.com> writes:
Keith Thompson wrote On 12/19/05 18:32,:
August Karlstrom <fu********@comhem.se> writes:
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);


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.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Dec 20 '05 #5

P: n/a


Keith Thompson wrote On 12/20/05 14:45,:
Eric Sosman <er*********@sun.com> writes:
Keith Thompson wrote On 12/19/05 18:32,:
August Karlstrom <fu********@comhem.se> writes:
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);


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.


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 ...)

--
Er*********@sun.com

Dec 20 '05 #6

P: n/a
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

--
I am the "ILOVEGNU" signature virus. Just copy me to your
signature. This email was infected under the terms of the GNU
General Public License.
Dec 21 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.