Jump to content
  • Advertisement
Sign in to follow this  
hoihoi8

Linked List indirection errors

This topic is 4861 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello, I'm having problems making a linked list in C. My structure looks like typedef struct BOB_TYP { data..... struct BOB_TYP *next; }BOB, *BOB_PTR; I declare a pointer to it externally in a .h so it is global extern BOB *ghost_ptr; I then declare it in declarations.cpp so all cpps can see it BOB *ghost_ptr; ghost_ptr = (BOB *) malloc(sizeof(BOB) ); When I build the code I get these errors: error C2501: 'ghost_ptr' : missing storage-class or type specifiers error C2040: 'ghost_ptr' : 'int' differs in levels of indirection from 'struct BOB_TYP *' error C2440: 'initializing' : cannot convert from 'struct BOB_TYP *' to 'int' Are there any glaring errors in my code that i'm missing. Any help would be greatly appriciated. Thanks, Josh

Share this post


Link to post
Share on other sites
Advertisement
Forgive me for asking, isn't there in C, or, C#, or C++, a 'TList' or a 'TObjectList' Feature (like in Delphi).

in that way you don't need any linked lists anymore! They are pain!

Linked List, if you do not really understand the way they work, they can be a real pain. A linked List is just a bunch a Structs (In pascal called Record) which are dynamically placed on the heap.

In order to solve your problem I'd suggest to study, deeply, the nature of Linked Lists.

Best Regards,
Marmin.

Share this post


Link to post
Share on other sites
It seems to me that all declarations aren't 'seeing' BOB. Put the typedef for BOB into a.h and include a.h in any cpp file that needs to declare a variable of type BOB.


Be sure to wrap this in a function

ghost_ptr = (BOB *) malloc(sizeof(BOB) );

Share this post


Link to post
Share on other sites
This doesn't make much sense to me, but if I move the line:

ghost_ptr = (BOB *) malloc(sizeof(BOB) );

into the main part of my prog, I no longer get the errors. Not really sure why I can't call the memory right after I declare it. I'm kinda new to using multiple cpps.

Thanks for your replies... Josh

Share this post


Link to post
Share on other sites
That's because you can't put arbitrary code at global scope. Try BOB *ghost_ptr = (BOB *) malloc(sizeof(BOB) );, so that it is an initialization.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!