Qbasicnews.com

Full Version: GCC help
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Is there a way to have a struct hold an pointer to an instance of itself?


Code:
typedef struct{
     int size;
     int blocksize;
     cache *subcache;
} cache;

I know that this code doesn't work, is there a trick to doing it somehow?
Code:
typedef struct _cache{
     int size;
     int blocksize;
     cache *subcache;
} cache;

Try that. If it doesn't work, it's because I've been coding deprived for a while.
Looks like you're code deprived, it doesn't work :b

It's ok, I used to be good at C too, anyone else got an idea?
Have you tried just doing this:

Code:
typedef struct cache{
     int size;
     int blocksize;
     cache *subcache;
} cache;

?

It works for me anyway.
Yeah, I tried that, I got a parse error, same as the one with the underscore.
Code:
typedef struct cache_st
{
    int size;
    int blocksize;
    struct cache_st* subcache;
} cache_t;
That's it.

Thanks.