Re: Array pointers
Jens.Toerring_at_physik.fu-berlin.de
Date: 08/16/04
- Next message: Erik Max Francis: "Re: Array pointers"
- Previous message: P Gentry: "Re: Embedded SMTP Problems"
- In reply to: Erik Max Francis: "Re: Array pointers"
- Next in thread: Erik Max Francis: "Re: Array pointers"
- Reply: Erik Max Francis: "Re: Array pointers"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 16 Aug 2004 18:46:09 GMT
Erik Max Francis <max@alcyone.com> wrote:
> Jens.Toerring@physik.fu-berlin.de wrote:
>> A two-dimensional array like your
>>
>> int array[2][3];
>>
>> doesn't decay to a pointer to pointer to int but just a pointer to
>> int.
> No, it decays to an int *[3].
Sorry, yes you are correct (and using 'array' directly will still
results in a compiler warning). But what I really wanted to express
is that a two-dimensional array isn't a pointer-to-pointer. And
a more-dimensional array is in C basically a flat array with all
rows stored one after each other in memory. So, if you want to
write a function that prints two-dimensional int matrices of
arbitrary rank you must pass the function a pointer to the first
element, i.e. &array[0|[0] or array[0], plus the dimensions and
treat it in the function as a pointer to a flat array, using the
additional knowledge about how the elements are stored. Passing
the function 'array' itself usually works also since the resulting
pointer is typically the same address as that of the first element
of the array.
>> > and then when I run the binary, I get a segmentation fault.
>>
>> Yes, that was to be expected...
> Your proposal would also fail.
Why?
Regards, Jens
-- \ Jens Thoms Toerring ___ Jens.Toerring@physik.fu-berlin.de \__________________________ http://www.toerring.de
- Next message: Erik Max Francis: "Re: Array pointers"
- Previous message: P Gentry: "Re: Embedded SMTP Problems"
- In reply to: Erik Max Francis: "Re: Array pointers"
- Next in thread: Erik Max Francis: "Re: Array pointers"
- Reply: Erik Max Francis: "Re: Array pointers"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|