Tuesday, 15 February 2011

c - incompatible types in assignment of ‘int’ to ‘int [(((sizetype)(((ssizetype)m) -1)) 1)]’ -



c - incompatible types in assignment of ‘int’ to ‘int [(((sizetype)(((ssizetype)m) -1)) 1)]’ -

the next c code gives error:

incompatible types in assignment of ‘int’ ‘int [(((sizetype)(((ssizetype)m) -1)) 1)]’

on lines phone call recursive functions:

int mergesort(int arr[], int n) { if (n > 1) { int m = (int)(n / 2); int a1[m]; // array 1 --> 1 m int a2[n-m]; // array 2 --> m + 1 n int temp = m+1; (int = 0; < n; i++) { if (i == m) break; a1[i] = arr[i]; a2[i] = arr[temp++]; } a1 = mergesort(a1, m); //error happens here, assigning //integer integer array. a2 = mergesort(a2, n - m); arr = merge(a1, a2); } homecoming arr; }

what error mean?

there several errors:

c++ doesn't back upwards variable length arrays (a1[m]) - utilize std::vector instead. even if did, arrays can't reassigned, a1 =... illegal even if could, couldn't assign single int them. mergesort returns int (why that?)

c sorting

No comments:

Post a Comment