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

Array Arguments.....

P: n/a
Hi all,
Is there any difference between the following 2 function prototypes
which accepts an array as argument?

void foo(int arr[]);
void foo(int *arr);

Which of the 2 is the best method of declaring a function prototype
which has array as arguments?

Thanks
Nov 14 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
prashna wrote:
Hi all,
Is there any difference between the following 2 function prototypes
which accepts an array as argument?

void foo(int arr[]);
void foo(int *arr);
This is Question 6.4 in the comp.lang.c Frequently
Asked Questions (FAQ) list

http://www.eskimo.com/~scs/C-faq/top.html
Which of the 2 is the best method of declaring a function prototype
which has array as arguments?


Which is better: A pineapple or a pomegranate?

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

Nov 14 '05 #2

P: n/a
prashna wrote:
Is there any difference between the following 2 function prototypes
which accepts an array as argument?

void foo(int arr[]);
void foo(int *arr);
No.

It might be worth noting that in C89/C90 with the first didn't let you
to declare the pointer itself as 'const', i.e. declaration

void foo(int *const arr);

didn't have an equivalent in the first format. However, C99 removed this
limitation - declaration

void foo(int arr[const]);

is equivalent to the previous one. (Assuming that you care about
declaring function parameters as 'const'. I don't remember ever doing it
myself.)
Which of the 2 is the best method of declaring a function prototype
which has array as arguments?


They are equivalent, which means that this is a matter of personal
preferences and/or coding standards. There's no "best" here.

--
Best regards,
Andrey Tarasevich
Nov 14 '05 #3

P: n/a

"Eric Sosman" <er*********@sun.com> wrote
void foo(int arr[]);
void foo(int *arr);


Which is better: A pineapple or a pomegranate?

The [] notation is a snare unto newbies.
Nov 14 '05 #4

P: n/a
> It might be worth noting that in C89/C90 with the first didn't let you
to declare the pointer itself as 'const', i.e. declaration

void foo(int *const arr);

didn't have an equivalent in the first format. However, C99 removed this
limitation - declaration

void foo(int arr[const]);

is equivalent to the previous one.


This is a horrible equivalence IMO. They should have stuck with the first
declaration instead of introducing new confusing syntax.
Nov 14 '05 #5

P: n/a


Method Man wrote:
It might be worth noting that in C89/C90 with the first didn't let you
to declare the pointer itself as 'const', i.e. declaration

void foo(int *const arr);

didn't have an equivalent in the first format. However, C99 removed this
limitation - declaration

void foo(int arr[const]);

is equivalent to the previous one.


This is a horrible equivalence IMO. They should have stuck with the first
declaration instead of introducing new confusing syntax.


I guess they did it only as they already had to do it for the
static keyword ( "int foo (int bar[static 3])" tells you that
you can safely access bar[0] through bar[2] ).

-Michael
--
E-Mail: Mine is a gmx dot de address.

Nov 14 '05 #6

P: n/a
"Michael Mair" <Mi**********@invalid.invalid> wrote in message
news:30*************@uni-berlin.de...


Method Man wrote:
It might be worth noting that in C89/C90 with the first didn't let you
to declare the pointer itself as 'const', i.e. declaration

void foo(int *const arr);

didn't have an equivalent in the first format. However, C99 removed this
limitation - declaration

void foo(int arr[const]);

is equivalent to the previous one.


This is a horrible equivalence IMO. They should have stuck with the first
declaration instead of introducing new confusing syntax.


I guess they did it only as they already had to do it for the
static keyword ( "int foo (int bar[static 3])" tells you that
you can safely access bar[0] through bar[2] ).


Was this syntax discussed in the ISO meetings ?

int[3] bar
int foo(int[3] bar)

--
Chqrlie.
Nov 14 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.