Qbasicnews.com

General => General Programming => Topic started by: wallace on November 29, 2006, 07:28:30 PM



Title: GCC help
Post by: wallace on November 29, 2006, 07:28:30 PM
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?


Title: GCC help
Post by: thegrogen on November 30, 2006, 12:08:51 AM
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.


Title: GCC help
Post by: wallace on November 30, 2006, 12:04:36 PM
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?


Title: GCC help
Post by: Zap on November 30, 2006, 12:32:14 PM
Have you tried just doing this:

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


?

It works for me anyway.


Title: GCC help
Post by: wallace on November 30, 2006, 12:41:50 PM
Yeah, I tried that, I got a parse error, same as the one with the underscore.


Title: GCC help
Post by: shiftLynx on November 30, 2006, 01:06:19 PM
Code:

typedef struct cache_st
{
    int size;
    int blocksize;
    struct cache_st* subcache;
} cache_t;


Title: GCC help
Post by: wallace on November 30, 2006, 04:28:04 PM
That's it.

Thanks.