Re: why it doesn't work?



Chief wrote:

if B is a 1D array (for instance int B[3]) and C is an int* pointer
(int*) then i can write C=B and everything will be cool.
but if B is a 2D array (for instance int B[3][5]) and C ia an int**
pointer (int**) then the same line , C=B, generates a warning
(incompatible types) and further use of C as a 2D array gets a runtime
error.....

That's right.

y is this happening???

"Why". It's happening because B evaluates [1] to a pointer to its first
element, which is an array of 5 ints, so it's pointer-to-array-5-int,
not pointer-to-int.

especially when we know that *(*(B+1)+2)
is legal !!

Because *(B+1) [ie, B[1]] is an array-of-5-ints, which evaluates
to pointer-to-int.

Declare B appropriately. Isn't there a FAQ about this?

[1] In value context, ie not as the operand to sizeof or &.

--
Chris "electric hedgehog" Dollin
Scoring, bah. If I want scoring I'll go play /Age of Steam/.

.



Relevant Pages

  • Re: detecting 64-bitness inside a program
    ... > The thing is that 64 bit yes or no is not very useful information ... pointer-to-int typecast and on some platforms gcc warns me that it may ... like to get rid of that warning. ... More specifically I divide a pointer value by a prime number for the ...
    (comp.unix.programmer)
  • Re: detecting 64-bitness inside a program
    ... > The thing is that 64 bit yes or no is not very useful information ... pointer-to-int typecast and on some platforms gcc warns me that it may ... like to get rid of that warning. ... More specifically I divide a pointer value by a prime number for the ...
    (comp.unix.solaris)