473,804 Members | 3,602 Online
Bytes | Software Development & Data Engineering Community
+ 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 2189
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********@com hem.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_Keit h) 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********@com hem.se> writes:
What's the cause of the inconsistency between variable and parameter
declaration s 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*********@su n.com> writes:
Keith Thompson wrote On 12/19/05 18:32,:
August Karlstrom <fu********@com hem.se> writes:
What's the cause of the inconsistency between variable and parameter
declaratio ns 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_Keit h) 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*********@su n.com> writes:
Keith Thompson wrote On 12/19/05 18:32,:
August Karlstrom <fu********@com hem.se> writes:
What's the cause of the inconsistency between variable and parameter
declaration s 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
4949
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 least) and I want to check I've understood it correctly. The code I wrote was. std::istringstream buf("abc"); std::vector<char> vec(std::istream_iterator<char>(buf), std::istream_iterator<char>());
6
5200
by: Andreas Wachowski | last post by:
Hi, consider the following program: // -------------- class A { public: A(int i) { } };
10
2672
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 declaration of a function pointer variable called fp: void (*fp)(void *); What does the syntax above mean? I can only digest it as void * fp, i.e. fp is a pointer to void.
23
19206
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
2074
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
2730
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 function, it is global regardless of whether it's declared with or without "var" * When it is declared inside a function, if declared with "var", it's local, if not, it's global
4
6117
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
2355
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
2047
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 the same file (.c + all relevant .h's)? e.g.
0
9705
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9576
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10074
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9138
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7613
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5647
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4291
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 we have to send another system
2
3809
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2983
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.