
-----------------------------------
DtY
Fri Feb 26, 2010 8:25 pm

passing argument 1 of ?find? from incompatible pointer type
-----------------------------------
I'm getting this warning from from my compiler, but as far as I can tell, all is right. When I run the program it segfaults.

Here are the four important lines:
int find(char **arr, char *se) {
/***/
char names

I'm getting the warning from both lines that call that function.

-----------------------------------
chrisbrown
Sat Feb 27, 2010 2:03 am

RE:passing argument 1 of ?find? from incompatible pointer type
-----------------------------------
You can only have one dynamic length when  passing multidimensional arrays in C. I'm wondering what you're trying to do, though. If names a one-dimensional array of strings (of max size 14?), change char names[10][15] to *names[10]. If it's a 2D array of chars, you could change **arr to *arr[15], which is the type of names.

-----------------------------------
DtY
Sat Feb 27, 2010 11:59 am

RE:passing argument 1 of ?find? from incompatible pointer type
-----------------------------------
Changing the argument to char arr[10][15] worked, thanks.

Why can't you pass a multidemsnional array with an unknown size? Isn't it just an array of pointers?

-----------------------------------
chrisbrown
Sat Feb 27, 2010 1:03 pm

Re: passing argument 1 of ?find? from incompatible pointer type
-----------------------------------
Not the way you've defined it. When you use the varof size y. 

If you used *var#include 

int main() {
	
	int i

-----------------------------------
DtY
Sat Feb 27, 2010 2:09 pm

RE:passing argument 1 of ?find? from incompatible pointer type
-----------------------------------
So when I create an array [5][3], it does not create an array with five pointers, pointing to an array with a length three, it creates a single array with size 5*3?

(If I'm understanding that right)

Is there any way to "trick" the compiler, so if I were to malloc(5*3*sizeof(int)), I could access it as [a][b], instead of [5*a+b]?

[edit] Is this part of Ansi C, or is it an optimization that compilers tend to do?

-----------------------------------
chrisbrown
Sat Feb 27, 2010 4:05 pm

Re: RE:passing argument 1 of ?find? from incompatible pointer type
-----------------------------------
So when I create an array 
Yes, as far as I understand it. I believe the compiler basically does you a favour by doing the math for you when using more than one dimension.

Is there any way to "trick" the compiler, so if I were to malloc(5*3*sizeof(int)), I could access it as 
Well, it's not pretty, but you could cast it to an array of second dimension size 3:
int **a = malloc(5*3*sizeof(int));
( (int(*)

Is this part of Ansi C, or is it an optimization that compilers tend to do?
I'm fairly sure it's standard. IIRC, the [] notation allocates on the stack, while * indicates heap allocation (through malloc'ing).[/quote]

-----------------------------------
DtY
Sat Feb 27, 2010 4:29 pm

RE:passing argument 1 of ?find? from incompatible pointer type
-----------------------------------
So is all memory that's not malloc()ed stored on the stack? Is that why it's suggested to create all arrays that are bigger than 1kB with malloc()?

Btw, the heap is just memory, right, and 'the stack' is referring to the call stack?

-----------------------------------
chrisbrown
Sat Feb 27, 2010 4:35 pm

RE:passing argument 1 of ?find? from incompatible pointer type
-----------------------------------
Yes and yes. That's also why you don't need to free anything on the stack, that space is dynamically deallocated when the function returns.

-----------------------------------
DtY
Sat Feb 27, 2010 4:59 pm

RE:passing argument 1 of ?find? from incompatible pointer type
-----------------------------------
Thanks for all the help, it's appreciated
