Function parameter lists 
Author Message
 Function parameter lists

Why do function parameter lists not follow the same rules as for struct
element lists?

Compare:
int foo (long a, long b, long c, int i, int j, char *s);

To:
int foo (long a, b, c; int i, j; char *s);

I think the latter avoids unnecessary duplication of type names.

--
Simon.



Sun, 23 May 2004 15:47:02 GMT  
 Function parameter lists

Quote:
> Why do function parameter lists not follow the same rules as for struct
> element lists?

> Compare:
> int foo (long a, long b, long c, int i, int j, char *s);

> To:
> int foo (long a, b, c; int i, j; char *s);

> I think the latter avoids unnecessary duplication of type names.

That is probably, because functions arn't structs, but the best
answer you can probably get to that question is, because the
standard defines it that way.

--

"LISP  is worth learning for  the profound enlightenment  experience
you will have when you finally get it; that experience will make you
a better programmer for the rest of your days."   -- Eric S. Raymond



Sun, 23 May 2004 16:00:55 GMT  
 Function parameter lists

Quote:

> Why do function parameter lists not follow the same rules as for struct
> element lists?

> Compare:
> int foo (long a, long b, long c, int i, int j, char *s);

> To:
> int foo (long a, b, c; int i, j; char *s);

> I think the latter avoids unnecessary duplication of type names.

If your function has enough parameters that it makes a
difference, you should probably consider changing your
parameter-passing strategy.


Sun, 23 May 2004 16:00:47 GMT  
 Function parameter lists


Quote:
>Why do function parameter lists not follow the same rules as for struct
>element lists?

>Compare:
>int foo (long a, long b, long c, int i, int j, char *s);

>To:
>int foo (long a, b, c; int i, j; char *s);

In single-statement declarations of multiple
same-type objects,
e.g.

int a,b,c;

.. The comma serves to delimit the identifiers.

In a function parameter list, e.g.

void func(int a, int b, int c)

... the comma serves to delimit the parameters, each of
which is expressed with a type name and optional identifier.
Consider the combination of a type with an identifer as a single
entity (parameter).

Quote:
>I think the latter avoids unnecessary duplication of type names.

Each paramter's type must be specified.  Hardly what I'd
call unnecessary. :-)

-Mike



Sun, 23 May 2004 16:41:01 GMT  
 Function parameter lists


Quote:
>Why do function parameter lists not follow the same rules as for struct
>element lists?

>Compare:
>int foo (long a, long b, long c, int i, int j, char *s);

As a declaration this can be shortend to

int foo (long, long, long, int, int, char *);

Quote:
>To:
>int foo (long a, b, c; int i, j; char *s);

I guess that's a possibility, although for specifying only types in
declarations it would have to be rearranged significantly.

Quote:
>I think the latter avoids unnecessary duplication of type names.

C's prototype syntax was blagged from C++ so your question is probably
best asked in comp.lang.c++.

--
-----------------------------------------


-----------------------------------------



Sun, 23 May 2004 19:22:04 GMT  
 Function parameter lists
This kind of function definition syntax is supported in C;

int foo (a, b, c, d, e, f)
long a,b,c;
int d,e;
char* f;
{

Quote:
}

Rgds,

Anand

Quote:



> >Why do function parameter lists not follow the same rules as for struct
> >element lists?

> >Compare:
> >int foo (long a, long b, long c, int i, int j, char *s);

> As a declaration this can be shortend to

> int foo (long, long, long, int, int, char *);

> >To:
> >int foo (long a, b, c; int i, j; char *s);

> I guess that's a possibility, although for specifying only types in
> declarations it would have to be rearranged significantly.

> >I think the latter avoids unnecessary duplication of type names.

> C's prototype syntax was blagged from C++ so your question is probably
> best asked in comp.lang.c++.



Mon, 24 May 2004 13:53:56 GMT  
 Function parameter lists

Quote:

> This kind of function definition syntax is supported in C;

> int foo (a, b, c, d, e, f)
> long a,b,c;
> int d,e;
> char* f;
> {

> }

Supported, but deprecated.


Mon, 24 May 2004 13:57:54 GMT  
 Function parameter lists


Quote:
>This kind of function definition syntax is supported in C;

>int foo (a, b, c, d, e, f)
>long a,b,c;
>int d,e;
>char* f;
>{

>}

True, but it isn't a prototype and lacks much of the required type checking
of prototypes. It should therefore be avoided.

--
-----------------------------------------


-----------------------------------------



Tue, 25 May 2004 06:53:00 GMT  
 Function parameter lists

Quote:

>This kind of function definition syntax is supported in

nonstandard, 'classical'

Quote:
> C;

>int foo (a, b, c, d, e, f)
>long a,b,c;
>int d,e;
>char* f;
>{

>}

This form is *not* supported by ISO/IEC standard C.

-Mike



Wed, 26 May 2004 08:07:06 GMT  
 Function parameter lists

Quote:


> >int foo (a, b, c, d, e, f)
> >long a,b,c;
> >int d,e;
> >char* f;
> >{

> >}

> This form is *not* supported by ISO/IEC standard C.

Yes, it is, both C89 and C99.


Wed, 26 May 2004 08:00:46 GMT  
 Function parameter lists

Quote:


>> >int foo (a, b, c, d, e, f)
>> >long a,b,c;
>> >int d,e;
>> >char* f;
>> >{

>> >}

>> This form is *not* supported by ISO/IEC standard C.

>Yes, it is, both C89 and C99.

But its not only deprecated, but also does not act as a prototype and
thus disallows the compiler from performing such strict typechecking.

--
Mark McIntyre
CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>



Wed, 26 May 2004 08:38:53 GMT  
 Function parameter lists

Quote:





Quote:
>> >int foo (a, b, c, d, e, f)
>> >long a,b,c;
>> >int d,e;
>> >char* f;
>> >{

>> >}

>> This form is *not* supported by ISO/IEC standard C.

>Yes, it is, both C89 and C99.

Oops, should have said 'deprecated'.
I've never liked that style anyway. :-)

-Mike



Wed, 26 May 2004 08:57:59 GMT  
 Function parameter lists

Quote:


> >[K&R1 function definition is] both C89 and C99.

> But its not only deprecated, but also does not act as a prototype and
> thus disallows the compiler from performing such strict typechecking.

Correct it's not a prototype and so does not convert arguments
except by the default argument promotions and does not
_require_ diagnosis of incorrect/inconvertible argument types,
but like any other UB diagnosis is permitted, and in this case
is often possible without runtime cost and thus "in the spirit of C".

--
- David.Thompson 1 now at worldnet.att.net



Fri, 04 Jun 2004 14:39:55 GMT  
 
 [ 13 post ] 

 Relevant Pages 

1. Empty Function parameter lists

2. Unable to browse code through Class View when I have a struct in the specific function parameter list!

3. Calling DLL functions without known function name, parameter-list until run-time

4. Correct rules for function macro parameter lists

5. dynamic parameter list for external function

6. Preferred empty parameter list function declaration.

7. Call a function in a function with name of a function as parameter

8. function parameters: default value, optional parameter

9. Question : A generic function to retrieve the call parameters of a function

10. Question : A generic function to retrieve the call parameters of a function

11. Function Parameters Change when function called?!

12. Passing C++ Class Member Function to as a C Callback Function Parameter

 

 
Powered by phpBB® Forum Software