Jump to content
  • Advertisement
Sign in to follow this  
GPHP

Struct & Union Allocation

This topic is 3861 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

Hi, I'm working on a segment of C code where i have something similar to the following: struct ioe_stream { unsigned char stream_type; unsigned int stream_flags; union { unsigned char std; struct { char* file_name; int handle; } file; struct { int ibuf_pos; int ibuf_len; } ibuf; } stream_data; }; and I'm trying to allocate it on heap using malloc... however when I try the following code: struct ioe_stream* s = malloc(sizeof(struct ioe_stream)); I get the following error: incomplete struct/union/enum ioe_stream: sizeof() I've been looking around for a while and cant quite figure out how to get this to work. Thanks

Share this post


Link to post
Share on other sites
Advertisement
It sounds like your struct definition is simply in another source file that you aren't #including.
Or is all of what you posted really in the same file with the struct preceeding the malloc call?

Share this post


Link to post
Share on other sites
Looks ok, compiles fine, passes splint. I'd say your problem is elsewhere.

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!