Re: why it doesn't work?
- From: Chris Dollin <chris.dollin@xxxxxx>
- Date: Wed, 31 Jan 2007 13:26:47 +0000
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/.
.
- References:
- why it doesn't work?
- From: Chief
- why it doesn't work?
- Prev by Date: Re: Read hex string to a buf
- Next by Date: Re: myfree(p)
- Previous by thread: why it doesn't work?
- Next by thread: Re: why it doesn't work?
- Index(es):
Relevant Pages
|