Re: Storing an array's subscript into a structure's member
Alex........ GOT IT !
========================================
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct tag_lb
{
long (*pmr)[5];
}lb;
lb* create_obj(long (*pmr)[5])
{
lb *ptr_lb = NULL;
ptr_lb = malloc (sizeof *ptr_lb);
ptr_lb->pmr = pmr;
return ptr_lb;
}
void f1(lb *pObj)
{
long t;
t = pObj->pmr[0][0];
t = pObj->pmr[0][1];
t = pObj->pmr[0][2];
}
int main()
{
lb *pObj = NULL;
long pmr[][5] = { {195, 194, 193, 111, 111 },
{194, 195, 112, 222, 111 } };
pObj = create_obj(&pmr[0]);
f1(pObj);
free(pObj);
return 0;
}
===================================
&pmr[0] where &pmr[0] is the address of the array's innitial base address of
the array. And it mathes the type of (long (*pmr)[5])
I am still digesting this one..... Thanks again Alex and everyone else!
--
Best regards
Roberto
"Alex Blekhman" wrote:
"Robby" wrote:
The basic difference is that I type casted the prm type to a
long* type.
Yes, cast will silent the compiler, but you'd better fix the
types, so the problem won't bite you at the runtime. Here's good
overview of arrays and pointers in C:
"Section 2. Arrays and Pointers"
http://www.lysator.liu.se/c/c-faq/c-2.html
Alex