selection-sort in C

J

Jorgen Grahn

void selectionSort(char s[], int len); int findSmallest(char s[], const
int idx_cur, const int len);
The consts on those parameters don't do much, but aren't actually wrong.

Just to show that function is not supposed to change its arguments.

That makes sense in the /definition/ of the function, provided you
want them to be const just like you might want any local variable to
be const.

It does not make sense in the /declaration/. The compiler will just
go "of course you can't change the argument, stupid -- C uses call by
value!"

/Jorgen
 
B

Ben Pfaff

pete said:
Also,
if the parameters are const qualified
in the definition of a function,
then they should also be const qualified in any prototype
of that function.

Are you are expressing a style preference here? I do not think
that the C standard makes that requirement.

GCC 4.4 doesn't warn about the following translation unit, even
with -Wall -Wextra -ansi -pedantic:

int f(int);
int f(const int x) { return x; }

int g(const int);
int g(int x) { return x; }
 
B

Ben Pfaff

pete said:
That's what a prototype is.

I think that you have missed the following parenthetical in
6.7.5.3 "Function declarators (including prototypes)":

(In the determination of type compatibility and of a
composite type, each parameter declared with function or
array type is taken as having the adjusted type and each
parameter declared with qualified type is taken as having
the unqualified version of its declared type.)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,952
Messages
2,570,116
Members
46,705
Latest member
BufordPala

Latest Threads

Top