473,657 Members | 2,355 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Named parameters

Hello,

Has there ever been any talk to adding named parameters to C? I enjoy
using them in my Python and Ada code and can see their usefulness in
C. I can envision an implementation where the naming would be based
upon a prototype and the parameter ordering could be worked out before
the linking phase (thus, no need to deal with changing a linker).

Just curious. I've done some googling and can't find any references,
but it is a bit of an obscure topic.

Thanks for the info,

Adam Ruth
Nov 13 '05 #1
48 3068
On 29 Oct 2003 19:35:21 -0800, ow***@hotmail.c om (Adam Ruth) wrote in
comp.lang.c:
Hello,

Has there ever been any talk to adding named parameters to C? I enjoy
using them in my Python and Ada code and can see their usefulness in
C. I can envision an implementation where the naming would be based
upon a prototype and the parameter ordering could be worked out before
the linking phase (thus, no need to deal with changing a linker).

Just curious. I've done some googling and can't find any references,
but it is a bit of an obscure topic.

Thanks for the info,

Adam Ruth


It has been discussed occasionally, on the newsgroup where it is
topical, namely news:comp.std.c , which discusses the past, present,
and future ANSI/ISO/IEC standard for the language. It is not really
on-topic here, where the topic is the C language as it actually is.

There has never been much support for it in the past, and it would
break an enormous amount of existing code. Google for prior
discussions on comp.std.c.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.l earn.c-c++ ftp://snurse-l.org/pub/acllc-c++/faq
Nov 13 '05 #2
ow***@hotmail.c om (Adam Ruth) writes:
Hello,

Has there ever been any talk to adding named parameters to C? I enjoy
using them in my Python and Ada code and can see their usefulness in
C. I can envision an implementation where the naming would be based
upon a prototype and the parameter ordering could be worked out before
the linking phase (thus, no need to deal with changing a linker).


Thanks, but our parameters already *have* names :-) :-p

I'm assuming you mean something like where if you have the
prototype:

void foo(int bar, int baz, int quux);

Then you could call foo() as:

foo(baz = 15, quux = 42, bar = 32);

That is, in any order, provided they are named.

We actually already have something similar for initializers of
structs and arrays now, but I guess nobody cared enough about
using it for function calls. I don't really, either, FWIW. But I
wouldn't really be surprised to see them in a future version of
the Standard.

If you really want it, it wouldn't be extremely difficult to
write your own preprocessor which would translate such calls
appropriately. :-)

--
Micah J. Cowan
mi***@cowan.nam e
Nov 13 '05 #3
On Thu, 30 Oct 2003 05:04:43 +0000, Jack Klein wrote:
On 29 Oct 2003 19:35:21 -0800, ow***@hotmail.c om (Adam Ruth) wrote in
comp.lang.c:
Hello,

Has there ever been any talk to adding named parameters to C? I enjoy
using them in my Python and Ada code and can see their usefulness in
C. I can envision an implementation where the naming would be based
upon a prototype and the parameter ordering could be worked out before
the linking phase (thus, no need to deal with changing a linker).

Just curious. I've done some googling and can't find any references,
but it is a bit of an obscure topic.

Thanks for the info,

Adam Ruth


It has been discussed occasionally

There has never been much support for it in the past,
and it would break an enormous amount of existing code.


It wouldn't necessarily break any existing code. It is just
necessary to come up with a syntax for it that would be a
syntax error in C99. For example:

int foo (int bar, int baz) {
...
int main (void) {
...
return foo (baz:15, bar:-23);
}

With grammar changes:

argument-expression-list:
argument-expression
argument-expression-list "," argument-expression

argument-expression:
assignment-expression
identifier ":" assignment-expression
Whether it's particularly useful is another question. With
default arguments in the function definition, I think it
probably would be a nice to have.

-Sheldon

Nov 13 '05 #4
On Thu, 30 Oct 2003 02:03:48 -0500, Sheldon Simms
<sh**********@y ahoo.com> wrote in comp.lang.c:
On Thu, 30 Oct 2003 05:04:43 +0000, Jack Klein wrote:
On 29 Oct 2003 19:35:21 -0800, ow***@hotmail.c om (Adam Ruth) wrote in
comp.lang.c:
Hello,

Has there ever been any talk to adding named parameters to C? I enjoy
using them in my Python and Ada code and can see their usefulness in
C. I can envision an implementation where the naming would be based
upon a prototype and the parameter ordering could be worked out before
the linking phase (thus, no need to deal with changing a linker).

Just curious. I've done some googling and can't find any references,
but it is a bit of an obscure topic.

Thanks for the info,

Adam Ruth


It has been discussed occasionally

There has never been much support for it in the past,
and it would break an enormous amount of existing code.


It wouldn't necessarily break any existing code. It is just
necessary to come up with a syntax for it that would be a
syntax error in C99. For example:

int foo (int bar, int baz) {
...
int main (void) {
...
return foo (baz:15, bar:-23);
}

With grammar changes:

argument-expression-list:
argument-expression
argument-expression-list "," argument-expression

argument-expression:
assignment-expression
identifier ":" assignment-expression
Whether it's particularly useful is another question. With
default arguments in the function definition, I think it
probably would be a nice to have.

-Sheldon


That's not the problem, that's easy.

The real problem lies in the untold number of existing programs where
there is more than one prototype for the same function, with different
names.

Consider even, in one source file:

int func(int one, int two);

/* stuff */

int func(int two, int one)
{
/* ... */
return some_thing;
}

/* still later */

int otherfunc(void)
{
int x = /* whatever */;
int y = /* something else */;

int z = func(one:x, two:y);
}

Other than the named parameters in the call, the above is perfectly
legal C89 and C99.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.l earn.c-c++ ftp://snurse-l.org/pub/acllc-c++/faq
Nov 13 '05 #5
On Thu, 30 Oct 2003 07:28:47 +0000, Jack Klein wrote:
On Thu, 30 Oct 2003 02:03:48 -0500, Sheldon Simms
<sh**********@y ahoo.com> wrote in comp.lang.c:
On Thu, 30 Oct 2003 05:04:43 +0000, Jack Klein wrote:
> On 29 Oct 2003 19:35:21 -0800, ow***@hotmail.c om (Adam Ruth) wrote in
> comp.lang.c:
>
>> Has there ever been any talk to adding named parameters to C?
>
> It has been discussed occasionally
>
> There has never been much support for it in the past,
> and it would break an enormous amount of existing code.


It wouldn't necessarily break any existing code. It is just
necessary to come up with a syntax for it that would be a
syntax error in C99.


That's not the problem, that's easy.

The real problem lies in the untold number of existing programs where
there is more than one prototype for the same function, with different
names.

Consider even, in one source file:

int func(int one, int two);

/* stuff */

int func(int two, int one)
{
/* ... */
return some_thing;
}

/* still later */

int otherfunc(void)
{
int x = /* whatever */;
int y = /* something else */;

int z = func(one:x, two:y);
}

Other than the named parameters in the call, the above is perfectly
legal C89 and C99.


Well it's really only a problem if the same name is used for
different parameters in different prototypes and not enough
other named arguments are supplied for disambiguation (which
is obviously impossible in your example).

I can think of several solutions to the problem off the top of
my head. The most comprehensive would require augmenting the syntax
for parameter-declarations. The minimal would simply declare the use
of named parameters in that situation to be undefined behavior.
In between would be to associate the arguments with the actual
parameters according to the "last" prototype seen.

-Sheldon

Nov 13 '05 #6
In <l6************ *************** *****@4ax.com> Jack Klein <ja*******@spam cop.net> writes:
On Thu, 30 Oct 2003 02:03:48 -0500, Sheldon Simms
<sh**********@ yahoo.com> wrote in comp.lang.c:
On Thu, 30 Oct 2003 05:04:43 +0000, Jack Klein wrote:
> There has never been much support for it in the past,
> and it would break an enormous amount of existing code.

Bullshit: it won't break any single piece of existing code, because
existing code doesn't use the (currently non-existing) feature.

Furthermore, I have yet to see a piece of C code where a function
declaration uses different parameter names than the function definition
(if the function declaration uses parameter names at all).

Any well written C program will contain exactly *one* declaration
and one definition for each global function it defines. Local functions
should have only the definition (except for the special case of
coroutines). More than that would create maintenance overheads.
It wouldn't necessarily break any existing code. It is just
necessary to come up with a syntax for it that would be a
syntax error in C99.

Exactly!
That's not the problem, that's easy.

The real problem lies in the untold number of existing programs where
there is more than one prototype for the same function, with different
names.


Non-issue: it is the one prototype that is currently in scope that
matters. The standard will simply have to specify which prototype is in
scope, if multiple prototypes are encountered: the first or the last.
Right now it doesn't matter, because the parameter names are ignored by
the compiler, only their types are relevant.

Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de
Nov 13 '05 #7
Jack Klein <ja*******@spam cop.net> wrote in message news:<6r******* *************** **********@4ax. com>...
On 29 Oct 2003 19:35:21 -0800, ow***@hotmail.c om (Adam Ruth) wrote in
comp.lang.c:
Hello,
[snip...]
Adam Ruth


It has been discussed occasionally, on the newsgroup where it is
topical, namely news:comp.std.c , which discusses the past, present,
and future ANSI/ISO/IEC standard for the language. It is not really
on-topic here, where the topic is the C language as it actually is.


I see the "this is off-topic" comment enough in this group to wonder
why that hasn't been put in the FAQ. Perhaps the name of the
newsgroup should change to be a bit more explicit about its topic.
Nov 13 '05 #8
Adam Ruth <ow***@hotmail. com> scribbled the following:
Jack Klein <ja*******@spam cop.net> wrote in message news:<6r******* *************** **********@4ax. com>...
On 29 Oct 2003 19:35:21 -0800, ow***@hotmail.c om (Adam Ruth) wrote in
comp.lang.c:
> Hello,
> [snip...]
> Adam Ruth
It has been discussed occasionally, on the newsgroup where it is
topical, namely news:comp.std.c , which discusses the past, present,
and future ANSI/ISO/IEC standard for the language. It is not really
on-topic here, where the topic is the C language as it actually is.

I see the "this is off-topic" comment enough in this group to wonder
why that hasn't been put in the FAQ. Perhaps the name of the
newsgroup should change to be a bit more explicit about its topic.


What, comp.lang.c isn't enough to tell you that this newsgroup is
about the computer language C?
Contrary to what people might think, comp.std.c is for the computer
standard about C, not the C defined in that standard.

It's really rather easy to figure out, once you grasp the idea that
Usenet newsgroup names are parsed in a strict left-to-right fashion.

comp: something about computers
comp.lang: something about computer languages
comp.lang.c: the computer language C

comp: something about computers
comp.std: something about computer standards
comp.std.c: the computer standard about C

***THE WRONG WAY!***
comp: something about computers
comp..c: something about the computer language C
comp.std.c: the C defined in the computer standard

See how the middle row skips over one part of the name and the bottom
row goes back to it? That's not how left-to-right parsing works.

--
/-- Joona Palaste (pa*****@cc.hel sinki.fi) ------------- Finland --------\
\-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
"You will be given the plague."
- Montgomery Burns
Nov 13 '05 #9
In message <bn**********@o ravannahka.hels inki.fi>
Joona I Palaste <pa*****@cc.hel sinki.fi> wrote:
Adam Ruth <ow***@hotmail. com> scribbled the following:
Jack Klein <ja*******@spam cop.net> wrote in message news:<6r******* *************** **********@4ax. com>...
On 29 Oct 2003 19:35:21 -0800, ow***@hotmail.c om (Adam Ruth) wrote in
comp.lang.c:

> Hello,
> [snip...]
> Adam Ruth

It has been discussed occasionally, on the newsgroup where it is
topical, namely news:comp.std.c , which discusses the past, present,
and future ANSI/ISO/IEC standard for the language. It is not really
on-topic here, where the topic is the C language as it actually is.
I see the "this is off-topic" comment enough in this group to wonder
why that hasn't been put in the FAQ. Perhaps the name of the
newsgroup should change to be a bit more explicit about its topic.


What, comp.lang.c isn't enough to tell you that this newsgroup is
about the computer language C?


No need to get sarky.
It's really rather easy to figure out, once you grasp the idea that
Usenet newsgroup names are parsed in a strict left-to-right fashion.

comp: something about computers
comp.lang: something about computer languages
comp.lang.c: the computer language C


I think the point is that in the absence of an official charter, there
is an implicit ".iso-standard" at the end of "comp.lang. c", leaving anything
even vaguely system-specific or only partially portable without a home.
Most other comp.lang.* groups aren't that intolerant.

I mean, for example, what newsgroup would you discuss some detail of the EDG
compiler in? In the absence of a specific newsgroup, normal Usenet etiquette
would suggest comp.lang.c to be the closest match. My point is that it's no
use shouting "off-topic" at posters if you haven't got somewhere better for
them to go. And I don't really believe that more general groups like
"comp.programmi ng" are better for something that is C-related.

As for suggestions about things that could be added to C, surely it's
reasonable to start the discussion in comp.lang.c? It's not as though the
original poster was necessarily wanting to launch straight into the
standardisation process.

Sometimes I get the feeling that a lot of the regulars only come here to
be unpleasant to newcomers and score pedantry points off of each other.
More than the Usenet average, I mean. Couldn't we hive off all the pedantry
to comp.lang.c.sta ndard or something?

--
Kevin Bracey, Principal Software Engineer
Tematic Ltd Tel: +44 (0) 1223 503464
182-190 Newmarket Road Fax: +44 (0) 1223 503458
Cambridge, CB5 8HE, United Kingdom WWW: http://www.tematic.com/
Nov 13 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

66
4976
by: Darren Dale | last post by:
Hello, def test(data): i = ? This is the line I have trouble with if i==1: return data else: return data a,b,c,d = test()
9
1469
by: Wiktor Zychla | last post by:
Hello, I wonder why the delegate declaration needs named parameters? public delegate void MyDelegate( int a, int b ); // ok public delegate void MyDelegate( int, int ); // compiler error C allows to define both: typedef void (*MyDelegate)(int); // ok
18
3447
by: Peter Hardy | last post by:
Hi Guys, Can I use named parameters in C# Methods. i.e doFoo(fname="do", lname="Foo"); Cheers, Pete
8
3036
by: cody | last post by:
Why doesn't C# allow default parameters for methods? An argument against I hear often is that the default parameters would have to be hardbaken into the assembly, but why? The Jit can take care of this, if the code is jitted the "push xyz" instructions of the actual default values can be inserted. To make things simpler and better readable I'd make all default parameters named parameters so that you can decide for yourself why one to...
17
2148
by: Ben R. | last post by:
I'm reading about attribute classes and specifically, named versus positional parameters. Was this implimented instead of multiple constructors for flexibility or is there another reason I'm missing? -Ben
3
2612
by: Adam Hartshorne | last post by:
What is named parameter mechanism? Any ideas? I am looking through some code and there is a comment saying "VC++ has trouble with the named parameters mechanism", which i have no idea what this means. Any help much appreciated, Adam
14
3262
by: cody | last post by:
I got a similar idea a couple of months ago, but now this one will require no change to the clr, is relatively easy to implement and would be a great addition to C# 3.0 :) so here we go.. To make things simpler and better readable I'd make all default parameters named parameters so that you can decide for yourself which one to pass and which not, rather than relying on massively overlaoded methods which hopefully provide the best...
0
8312
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
8732
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8504
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8606
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
7337
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...
0
5632
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4159
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4318
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2732
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

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.