Sign in to follow this  
GPHP

Struct & Union Allocation

Recommended Posts

GPHP    122
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
iMalc    2466
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this