Multiple errors on compiling quicksort program's code file in C, on Cygwin.
by ajiten from LinuxQuestions.org on (#6CB9F)
Have the Quicksort program, in which had to implement only the main, cmp(comparator), & selectPivotIndex functions.
Rest program functions are copied from the book: Algorithms in a nutshell, by George T. Heineman.
Have built the following code, and compiled using the :
Code: gcc --save-temps --verbose quicksort.c -o quicksortThough, once the errors subside, will use the option:
Code: cc -pedantiC -W -Wall -Werror quicksort.c -o quicksort
Code:#include<stdio.h>
int partition(void **, int, int *, int, int , int);
int cmp(const void *, const void*);
void do_qsort(void **, int *, int, int);
int selectPivotIndex(void **, int int);
int main(){
void ** vals;//array of pointers
int total_elements;
return do_qsort(vals, total_elements-1, int(* cmp)(const void *, const void*));
}
void do_qsort(void **ar, int right, int(*cmp)(const void *, const void *), int left, int right){
int pivotIndex;
if (right<= left) return;
pivotIndex = selectPivotIndex(ar, left, right);
pivotIndex = partition(ar, cmp, left, right, pivotIndex);
do_qsort(ar, cmp, left, pivotIndex-1); do_qsort(ar, cmp, pivotInex+!, right);
}
int partition(void ** ar, int(* cmp)(const void*, const void*), int left, int right, int PivotIndex){
int idx, store; void *pivot = ar[pivotIndex]; void *tmp = ar[right];
ar[right] = ar[pivotIndex]; ar[pivotIndex]= tmp;
store = left;
for(idx= left; idx<right;idx++){
if(cmp(ar[idx], pivot <=0){
tmp = ar[idx]; ar[idx]=ar[store]; ar[store]=tmp; store++;
}
}
tmp= ar[right]; ar[right] = ar[store]; ar[store] = tmp;
return store;
}
int cmp(const void * a, const void *b)
{
if ((int*)a<=(int*)b) return 0;
else return 1;
}
int selectPivotIndex(void ** ar, int left, int right)
{
int median;
median = (left+right)/2;
if(median %2==0) median = median +1;
return median;
}Have got many errors, as shown below:
Code:quicksort.c: In function imaini:
quicksort.c:10:49: error: expected expression before iinti
10 | return do_qsort(vals, total_elements-1, int(* cmp)(const void *, const void*));
| ^~~
quicksort.c:10:45: warning: passing argument 2 of ido_qsorti makes pointer from integer without a cast [-Wint-conversion]
10 | return do_qsort(vals, total_elements-1, int(* cmp)(const void *, const void*));
| ~~~~~~~~~~~~~~^~
| |
| int
quicksort.c:4:24: note: expected iint *i but argument is of type iinti
4 | void do_qsort(void **, int *, int, int);
| ^~~~~
quicksort.c:10:16: error: too few arguments to function ido_qsorti
10 | return do_qsort(vals, total_elements-1, int(* cmp)(const void *, const void*));
| ^~~~~~~~
quicksort.c:4:6: note: declared here
4 | void do_qsort(void **, int *, int, int);
| ^~~~~~~~
quicksort.c: At top level:
quicksort.c:13:90: error: redefinition of parameter irighti
13 | void do_qsort(void **ar, int right, int(*cmp)(const void *, const void *), int left, int right){
| ~~~~^~~~~
quicksort.c:13:30: note: previous definition of irighti with type iinti
13 | void do_qsort(void **ar, int right, int(*cmp)(const void *, const void *), int left, int right){
| ~~~~^~~~~
quicksort.c:13:6: error: conflicting types for ido_qsorti; have ivoid(void **, int, int (*)(const void *, const void *), int, int)i
13 | void do_qsort(void **ar, int right, int(*cmp)(const void *, const void *), int left, int right){
| ^~~~~~~~
quicksort.c:4:6: note: previous declaration of ido_qsorti with type ivoid(void **, int *, int, int)i
4 | void do_qsort(void **, int *, int, int);
| ^~~~~~~~
quicksort.c: In function ido_qsorti:
quicksort.c:17:36: warning: passing argument 2 of ipartitioni makes integer from pointer without a cast [-Wint-conversion]
17 | pivotIndex = partition(ar, cmp, left, right, pivotIndex);
| ^~~
| |
| int (*)(const void *, const void *)
quicksort.c:2:24: note: expected iinti but argument is of type iint (*)(const void *, const void *)i
2 | int partition(void **, int, int *, int, int , int);
| ^~~
quicksort.c:17:41: warning: passing argument 3 of ipartitioni makes pointer from integer without a cast [-Wint-conversion]
17 | pivotIndex = partition(ar, cmp, left, right, pivotIndex);
| ^~~~
| |
| int
quicksort.c:2:29: note: expected iint *i but argument is of type iinti
2 | int partition(void **, int, int *, int, int , int);
| ^~~~~
quicksort.c:17:22: error: too few arguments to function ipartitioni
17 | pivotIndex = partition(ar, cmp, left, right, pivotIndex);
| ^~~~~~~~~
quicksort.c:2:5: note: declared here
2 | int partition(void **, int, int *, int, int , int);
| ^~~~~~~~~
quicksort.c:18:22: warning: passing argument 2 of ido_qsorti makes integer from pointer without a cast [-Wint-conversion]
18 | do_qsort(ar, cmp, left, pivotIndex-1); do_qsort(ar, cmp, pivotInex+!, right);
| ^~~
| |
| int (*)(const void *, const void *)
quicksort.c:13:30: note: expected iinti but argument is of type iint (*)(const void *, const void *)i
13 | void do_qsort(void **ar, int right, int(*cmp)(const void *, const void *), int left, int right){
| ~~~~^~~~~
quicksort.c:18:27: warning: passing argument 3 of ido_qsorti makes pointer from integer without a cast [-Wint-conversion]
18 | do_qsort(ar, cmp, left, pivotIndex-1); do_qsort(ar, cmp, pivotInex+!, right);
| ^~~~
| |
| int
quicksort.c:13:42: note: expected iint (*)(const void *, const void *)i but argument is of type iinti
13 | void do_qsort(void **ar, int right, int(*cmp)(const void *, const void *), int left, int right){
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
quicksort.c:18:9: error: too few arguments to function ido_qsorti
18 | do_qsort(ar, cmp, left, pivotIndex-1); do_qsort(ar, cmp, pivotInex+!, right);
| ^~~~~~~~
quicksort.c:13:6: note: declared here
13 | void do_qsort(void **ar, int right, int(*cmp)(const void *, const void *), int left, int right){
| ^~~~~~~~
quicksort.c:18:66: error: ipivotInexi undeclared (first use in this function); did you mean ipivotIndexi?
18 | do_qsort(ar, cmp, left, pivotIndex-1); do_qsort(ar, cmp, pivotInex+!, right);
| ^~~~~~~~~
| pivotIndex
quicksort.c:18:66: note: each undeclared identifier is reported only once for each function it appears in
quicksort.c:18:77: error: expected expression before i,i token
18 | do_qsort(ar, cmp, left, pivotIndex-1); do_qsort(ar, cmp, pivotInex+!, right);
| ^
quicksort.c:18:61: warning: passing argument 2 of ido_qsorti makes integer from pointer without a cast [-Wint-conversion]
18 | do_qsort(ar, cmp, left, pivotIndex-1); do_qsort(ar, cmp, pivotInex+!, right);
| ^~~
| |
| int (*)(const void *, const void *)
quicksort.c:13:30: note: expected iinti but argument is of type iint (*)(const void *, const void *)i
13 | void do_qsort(void **ar, int right, int(*cmp)(const void *, const void *), int left, int right){
| ~~~~^~~~~
quicksort.c:18:48: error: too few arguments to function ido_qsorti
18 | do_qsort(ar, cmp, left, pivotIndex-1); do_qsort(ar, cmp, pivotInex+!, right);
| ^~~~~~~~
quicksort.c:13:6: note: declared here
13 | void do_qsort(void **ar, int right, int(*cmp)(const void *, const void *), int left, int right){
| ^~~~~~~~
quicksort.c: At top level:
quicksort.c:21:5: error: conflicting types for ipartitioni; have iint(void **, int (*)(const void *, const void *), int, int, int)i
21 | int partition(void ** ar, int(* cmp)(const void*, const void*), int left, int right, int PivotIndex){
| ^~~~~~~~~
quicksort.c:2:5: note: previous declaration of ipartitioni with type iint(void **, int, int *, int, int, int)i
2 | int partition(void **, int, int *, int, int , int);
| ^~~~~~~~~
quicksort.c: In function ipartitioni:
quicksort.c:22:41: error: ipivotIndexi undeclared (first use in this function); did you mean iPivotIndexi?
22 | int idx, store; void *pivot = ar[pivotIndex]; void *tmp = ar[right];
| ^~~~~~~~~~
| PivotIndex
quicksort.c:26:38: warning: passing argument 2 of icmpi makes pointer from integer without a cast [-Wint-conversion]
26 | if(cmp(ar[idx], pivot <=0){
| ~~~~~~^~~
| |
| int
quicksort.c:26:38: note: expected iconst void *i but argument is of type iinti
quicksort.c:26:42: error: expected i)i before i{i token
26 | if(cmp(ar[idx], pivot <=0){
| ~ ^
| )
quicksort.c:29:8: error: expected expression before i}i token
29 | }
| ^
Rest program functions are copied from the book: Algorithms in a nutshell, by George T. Heineman.
Have built the following code, and compiled using the :
Code: gcc --save-temps --verbose quicksort.c -o quicksortThough, once the errors subside, will use the option:
Code: cc -pedantiC -W -Wall -Werror quicksort.c -o quicksort
Code:#include<stdio.h>
int partition(void **, int, int *, int, int , int);
int cmp(const void *, const void*);
void do_qsort(void **, int *, int, int);
int selectPivotIndex(void **, int int);
int main(){
void ** vals;//array of pointers
int total_elements;
return do_qsort(vals, total_elements-1, int(* cmp)(const void *, const void*));
}
void do_qsort(void **ar, int right, int(*cmp)(const void *, const void *), int left, int right){
int pivotIndex;
if (right<= left) return;
pivotIndex = selectPivotIndex(ar, left, right);
pivotIndex = partition(ar, cmp, left, right, pivotIndex);
do_qsort(ar, cmp, left, pivotIndex-1); do_qsort(ar, cmp, pivotInex+!, right);
}
int partition(void ** ar, int(* cmp)(const void*, const void*), int left, int right, int PivotIndex){
int idx, store; void *pivot = ar[pivotIndex]; void *tmp = ar[right];
ar[right] = ar[pivotIndex]; ar[pivotIndex]= tmp;
store = left;
for(idx= left; idx<right;idx++){
if(cmp(ar[idx], pivot <=0){
tmp = ar[idx]; ar[idx]=ar[store]; ar[store]=tmp; store++;
}
}
tmp= ar[right]; ar[right] = ar[store]; ar[store] = tmp;
return store;
}
int cmp(const void * a, const void *b)
{
if ((int*)a<=(int*)b) return 0;
else return 1;
}
int selectPivotIndex(void ** ar, int left, int right)
{
int median;
median = (left+right)/2;
if(median %2==0) median = median +1;
return median;
}Have got many errors, as shown below:
Code:quicksort.c: In function imaini:
quicksort.c:10:49: error: expected expression before iinti
10 | return do_qsort(vals, total_elements-1, int(* cmp)(const void *, const void*));
| ^~~
quicksort.c:10:45: warning: passing argument 2 of ido_qsorti makes pointer from integer without a cast [-Wint-conversion]
10 | return do_qsort(vals, total_elements-1, int(* cmp)(const void *, const void*));
| ~~~~~~~~~~~~~~^~
| |
| int
quicksort.c:4:24: note: expected iint *i but argument is of type iinti
4 | void do_qsort(void **, int *, int, int);
| ^~~~~
quicksort.c:10:16: error: too few arguments to function ido_qsorti
10 | return do_qsort(vals, total_elements-1, int(* cmp)(const void *, const void*));
| ^~~~~~~~
quicksort.c:4:6: note: declared here
4 | void do_qsort(void **, int *, int, int);
| ^~~~~~~~
quicksort.c: At top level:
quicksort.c:13:90: error: redefinition of parameter irighti
13 | void do_qsort(void **ar, int right, int(*cmp)(const void *, const void *), int left, int right){
| ~~~~^~~~~
quicksort.c:13:30: note: previous definition of irighti with type iinti
13 | void do_qsort(void **ar, int right, int(*cmp)(const void *, const void *), int left, int right){
| ~~~~^~~~~
quicksort.c:13:6: error: conflicting types for ido_qsorti; have ivoid(void **, int, int (*)(const void *, const void *), int, int)i
13 | void do_qsort(void **ar, int right, int(*cmp)(const void *, const void *), int left, int right){
| ^~~~~~~~
quicksort.c:4:6: note: previous declaration of ido_qsorti with type ivoid(void **, int *, int, int)i
4 | void do_qsort(void **, int *, int, int);
| ^~~~~~~~
quicksort.c: In function ido_qsorti:
quicksort.c:17:36: warning: passing argument 2 of ipartitioni makes integer from pointer without a cast [-Wint-conversion]
17 | pivotIndex = partition(ar, cmp, left, right, pivotIndex);
| ^~~
| |
| int (*)(const void *, const void *)
quicksort.c:2:24: note: expected iinti but argument is of type iint (*)(const void *, const void *)i
2 | int partition(void **, int, int *, int, int , int);
| ^~~
quicksort.c:17:41: warning: passing argument 3 of ipartitioni makes pointer from integer without a cast [-Wint-conversion]
17 | pivotIndex = partition(ar, cmp, left, right, pivotIndex);
| ^~~~
| |
| int
quicksort.c:2:29: note: expected iint *i but argument is of type iinti
2 | int partition(void **, int, int *, int, int , int);
| ^~~~~
quicksort.c:17:22: error: too few arguments to function ipartitioni
17 | pivotIndex = partition(ar, cmp, left, right, pivotIndex);
| ^~~~~~~~~
quicksort.c:2:5: note: declared here
2 | int partition(void **, int, int *, int, int , int);
| ^~~~~~~~~
quicksort.c:18:22: warning: passing argument 2 of ido_qsorti makes integer from pointer without a cast [-Wint-conversion]
18 | do_qsort(ar, cmp, left, pivotIndex-1); do_qsort(ar, cmp, pivotInex+!, right);
| ^~~
| |
| int (*)(const void *, const void *)
quicksort.c:13:30: note: expected iinti but argument is of type iint (*)(const void *, const void *)i
13 | void do_qsort(void **ar, int right, int(*cmp)(const void *, const void *), int left, int right){
| ~~~~^~~~~
quicksort.c:18:27: warning: passing argument 3 of ido_qsorti makes pointer from integer without a cast [-Wint-conversion]
18 | do_qsort(ar, cmp, left, pivotIndex-1); do_qsort(ar, cmp, pivotInex+!, right);
| ^~~~
| |
| int
quicksort.c:13:42: note: expected iint (*)(const void *, const void *)i but argument is of type iinti
13 | void do_qsort(void **ar, int right, int(*cmp)(const void *, const void *), int left, int right){
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
quicksort.c:18:9: error: too few arguments to function ido_qsorti
18 | do_qsort(ar, cmp, left, pivotIndex-1); do_qsort(ar, cmp, pivotInex+!, right);
| ^~~~~~~~
quicksort.c:13:6: note: declared here
13 | void do_qsort(void **ar, int right, int(*cmp)(const void *, const void *), int left, int right){
| ^~~~~~~~
quicksort.c:18:66: error: ipivotInexi undeclared (first use in this function); did you mean ipivotIndexi?
18 | do_qsort(ar, cmp, left, pivotIndex-1); do_qsort(ar, cmp, pivotInex+!, right);
| ^~~~~~~~~
| pivotIndex
quicksort.c:18:66: note: each undeclared identifier is reported only once for each function it appears in
quicksort.c:18:77: error: expected expression before i,i token
18 | do_qsort(ar, cmp, left, pivotIndex-1); do_qsort(ar, cmp, pivotInex+!, right);
| ^
quicksort.c:18:61: warning: passing argument 2 of ido_qsorti makes integer from pointer without a cast [-Wint-conversion]
18 | do_qsort(ar, cmp, left, pivotIndex-1); do_qsort(ar, cmp, pivotInex+!, right);
| ^~~
| |
| int (*)(const void *, const void *)
quicksort.c:13:30: note: expected iinti but argument is of type iint (*)(const void *, const void *)i
13 | void do_qsort(void **ar, int right, int(*cmp)(const void *, const void *), int left, int right){
| ~~~~^~~~~
quicksort.c:18:48: error: too few arguments to function ido_qsorti
18 | do_qsort(ar, cmp, left, pivotIndex-1); do_qsort(ar, cmp, pivotInex+!, right);
| ^~~~~~~~
quicksort.c:13:6: note: declared here
13 | void do_qsort(void **ar, int right, int(*cmp)(const void *, const void *), int left, int right){
| ^~~~~~~~
quicksort.c: At top level:
quicksort.c:21:5: error: conflicting types for ipartitioni; have iint(void **, int (*)(const void *, const void *), int, int, int)i
21 | int partition(void ** ar, int(* cmp)(const void*, const void*), int left, int right, int PivotIndex){
| ^~~~~~~~~
quicksort.c:2:5: note: previous declaration of ipartitioni with type iint(void **, int, int *, int, int, int)i
2 | int partition(void **, int, int *, int, int , int);
| ^~~~~~~~~
quicksort.c: In function ipartitioni:
quicksort.c:22:41: error: ipivotIndexi undeclared (first use in this function); did you mean iPivotIndexi?
22 | int idx, store; void *pivot = ar[pivotIndex]; void *tmp = ar[right];
| ^~~~~~~~~~
| PivotIndex
quicksort.c:26:38: warning: passing argument 2 of icmpi makes pointer from integer without a cast [-Wint-conversion]
26 | if(cmp(ar[idx], pivot <=0){
| ~~~~~~^~~
| |
| int
quicksort.c:26:38: note: expected iconst void *i but argument is of type iinti
quicksort.c:26:42: error: expected i)i before i{i token
26 | if(cmp(ar[idx], pivot <=0){
| ~ ^
| )
quicksort.c:29:8: error: expected expression before i}i token
29 | }
| ^