Re: Accessing via a pointer to 2d array.
From: Dan Pop (Dan.Pop_at_cern.ch)
Date: 11/11/03
- Next message: Zoran Cutura: "Re: Pointers, structs and memory allocations"
- Previous message: tekenenSPAM_at_BUSThotmailE.Rcom: "Re: [OT] Re: Asking if elements in struct arre zero"
- In reply to: Thes: "Re: Accessing via a pointer to 2d array."
- Next in thread: Dan Pop: "Re: Accessing via a pointer to 2d array."
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 11 Nov 2003 16:34:22 GMT
In <3FB0F51F.7020704@ctually.myaddress.com> Thes <not@ctually.myaddress.com> writes:
>Dan Pop wrote:
>>
>> The bug was elsewhere in your code. The value of *any* object, no matter
>> how large and complex, can be safely copied with memcpy.
>>
>Indeed. I've discovered that there is a difference between
>*StoredMatrix[i][j] and (*StoredMatrix)[i][j] which suprised me.
>
>What are the rules in these cases?
The [] operator having higher precedence, *StoredMatrix[i][j] is the same
as *(StoredMatrix[i][j]), which is NOT what you want in order to access
the element on row i, column j. StoredMatrix[i] is already sending you
beyond the array pointed to by StoredMatrix, if i is not 0.
To preserve your sanity, restrict yourself to pointers to "unidimensional"
arrays, as I've shown in my first post in this thread.
Dan
-- Dan Pop DESY Zeuthen, RZ group Email: Dan.Pop@ifh.de
- Next message: Zoran Cutura: "Re: Pointers, structs and memory allocations"
- Previous message: tekenenSPAM_at_BUSThotmailE.Rcom: "Re: [OT] Re: Asking if elements in struct arre zero"
- In reply to: Thes: "Re: Accessing via a pointer to 2d array."
- Next in thread: Dan Pop: "Re: Accessing via a pointer to 2d array."
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|