[prog] mutlitdimensional arrays in C

Isabelle Hurbain isabelle.hurbain at pasithee.net
Sat Oct 9 16:57:45 EST 2004

On Sat, 9 Oct 2004 10:47:35 -0400
aec <brat at magma.ca> wrote:

> This gave me some gcc warnings but the program did compile and run
> ex.8.12.c: In function `transposeArray':
> ex.8.12.c:15: warning: return makes integer from pointer without a
> cast
> I am not sure what these warnings mean, I havent done pointers yet
> in the book. Also, all my types are ints, so im confused about the
> "cast" in the error. 

Well, you actually do pointers without knowing it ;) as arrays are, in
fact, pointers. I guess you'll see that a bit later in the book so I
don't want to confuse you right now.

The warning (not an error because an error would make the compilation
fail) comes from your line :
  return n;
The thing is, you declared your return type as "int" and what you try to
return is n, which you declared as type int[5][4]. Hence the error :
int[5][4] is, as I told before, a pointer. So you are doing exactly what
gcc suggests to you : it waits an integer and you give him a pointer.
You don't actually need to return anything the way you do things. By the
way you can see that you do not use your return value ;)
The simplest thing that will make the warning disappear is to delete the
return n; line and put the return type to void.

Hoping to be clear (do not hesitate to growl if I'm not ;) )


More information about the Programming mailing list