Mostly Bollogs, I'm afraid

But occasionally, a glimmer of truth.
If you find one, please let me know.

Monday, 24 September 2012


I am struggling, C peeps.

I have:

struct thing {
 int i;

struct stuff {
 int i;
 thing *t;

stuff **pst;

There are many stuffs (in pst on the heap) each of which have many things which are allocated on the heap.

I know which stuff I want to access and which thing in the stuff. x is the element of thing I want.

So what I want to say is


The "(" is a syntax error which it shouldn't bloody well be, but it is.

Can I access that without something like

thing *t;

No, didn't think so.


Anonymous said...

Can't you access via array syntax?


with y adjusted to an array offset from x? (x/sizeof(t)) perhaps?

SadButMadLad said...

Assuming you want pst to be a pointer to an array of many pointers to stuff structures, then the following should work.

struct stuff *somestuff = *pst[x];
struct thing *something = somestuff->t;

SadButMadLad said...


struct stuff *somestuff = pst[x];
struct thing *something = somestuff->t;