473,473 Members | 2,125 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Variable/parameter declaration inconsistency

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
6 2176
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
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


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


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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: John Harrison | last post by:
I've seen cases before where it was intended to write a variable declaration but a function prototype was written instead (e.g. X x();) but I've come accross a new version of this (new to me at...
6
by: Andreas Wachowski | last post by:
Hi, consider the following program: // -------------- class A { public: A(int i) { } };
10
by: Adam Warner | last post by:
Hi all, Just before Christmas Chris Torek gave me some great advice about closures in C: <http://groups.google.co.nz/groups?selm=cqcl3k030vj%40news3.newsguy.com&output=gplain> It includes this...
23
by: Russ Chinoy | last post by:
Hi, This may be a totally newbie question, but I'm stumped. If I have a function such as: function DoSomething(strVarName) { ..... }
9
by: Joseph Turian | last post by:
Consider this code snippet which doesn't compile: struct DebugOptions { }; class Debug { public: Debug(const DebugOptions options) { _options = options; } private:
4
by: Ray | last post by:
Hello, I think I've had JavaScript variable scope figured out, can you please see if I've got it correctly? * Variables can be local or global * When a variable is declared outside any...
4
by: nospam_timur | last post by:
Let's say I have two files, myfile.h and myfile.c: myfile.h: int myfunction(int x); myfile.c: #include "myfile.h"
2
by: vlsidesign | last post by:
Here is my a portion of my program: #include <stdio.h> main() { int fahr, celsius; int lower, upper, step; int fc_conv(int fahr); ... snip ... }
3
by: SRoubtsov | last post by:
Dear all, Do you know whether ANSI C (or some other dialects) support the following: * a variable name coincides with a type name, * a structure/union field name coincides with a type name in...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.