| Home
| Calendar
| Mail Lists
| List Archives
| Desktop SIG
| Hardware Hacking SIG
Wiki | Flickr | PicasaWeb | Video | Maps & Directions | Installfests | Keysignings Linux Cafe | Meeting Notes | Linux Links | About BLU |
On Fri, Aug 29, 2008 at 08:16:35PM -0400, Ruben Safir wrote:
> On Fri, Aug 29, 2008 at 05:43:40PM -0400, Stephen Adler wrote:
> > Guys,
> >
> > I've got a standard c coding question which has been nagging me for a
> > while and I was wondering what you guys may think or have the correct
> > solution to this problem....
> >
> > Lets say I have a 2 dim array of data and the dimension sizes can change
> > depending on the specific data set. I can read in the x and y dimensions
> > from a file, then read in the x*y elements of the data a populate a
> > memory area x*y*elementsizeinbytes with the data. But now I want to
> > access the data. Without doing pointer arithmatic, is it possible to use
> > the standard [][] notation somehow?
> >
> > for example
> >
> > int *data;
> > x=getXDim();
> > y=getYDim();
> > data=(int *)malloc(x*y*sizeof(int));
> > readInData(x,y,data);
> > printf("Middle data element is %d\n",data[y][x]);
> >
> > but I know that that data[y][x] will barf on the compiler because the
> > compiler has no way of knowing what the y size of the "y" dimension is...
> >
> > Any suggestions on how to use the N-dimensional bracket notation in this
> > situation?
> >
> > Thanks.
> >
>