You are not logged in.
i have a two struct like so:
typedef struct {
uint8_t data[256];
} foo1;
typedef struct {
uint32_t data_ptr;
} foo2;
...
...
foo1 * ctx;
foo2 ply;
if i want to get the pointer to the data array in ctx and assigned to data_ptr would i do it like so:
ply.data_ptr = &(ctx->data);
Offline
There's a few problems here:
- data_ptr would need to be declared of type pointer in order to legally hold the address of another value.
- Barring that, you've also got a type mismatch. uint8_t != uint32_t
- Barring that, the data member of foo1 is an array, so referring to the member 'data' on its own implies an address, not a value. It would be valid to assign ctx->data to a pointer.
Offline
&(ctx->data) returns a pointer to an array of 256 integers. This type will look something like uint8_t (*data_ptr)[256]. Instead you should do what falconindy suggested above:
ply.data_ptr = ctx->data
To avoid gcc warnings (which you should always avoid), data_ptr needs to be declared the correct type of pointer. Since ctx->data by itself is nothing more than a pointer to an 8-bit wide integer you want (uint8_t *). ((void *) also works)
Offline
Also, ctx is a pointer to a foo1 structure. No where did you actually allocate memory, nor did you cause ctx to actually point at that memory. I realize this is not a complete program and this may have been implicit -- but it is worth noting.
Nothing is too wonderful to be true, if it be consistent with the laws of nature -- Michael Faraday
Sometimes it is the people no one can imagine anything of who do the things no one can imagine. -- Alan Turing
---
How to Ask Questions the Smart Way
Offline
I suggest you to give a read on http://pw1.netcom.com/~tjensen/ptr/pointers.htm to clear some concepts and grasp some interesting points.
Offline