Skip to main content
GameDev.net gamedev.net
🔒 Locked

C - Returning a struct

Started by I_Smell_Tuna Jan 23, 2006 at 10:26 PM 1 replies 600+ views
Original Post
I_Smell_Tuna
I_Smell_Tuna
I'm using Code::Blocks with the GCC compiler. I'm trying to return a structure from a function it says I have multiple definitions of a function. What is the propper way to return a structure from a function? Here is how I'm currently trying (and failing) to do it.

struct MY_STRUCT *FUNCTION(struct MY_STRUCT *Example)
{

}

MrUmbrellaHead
MrUmbrellaHead
//you may need to try using typedef
typedef struct
{

}MY_STRUCT;

//once done you pass it as any pointer
MY_STRUCT *FUNCTION(MY_STRUCT *Example)
{
}

Remember though that Example is a pointer, so changes occuring in the function change data at that memory address, this modifys the struct you actually passed in. This means you might not need to return a struct. If you are returning a struct you might need to consider using "new/delete" or "malloc/free" so that the memory is still valid after the function has been called.

I am uncertain if you are having trouble with C or gcc compiler so sorry if this post is not what you wanted.
I_Smell_Tuna
I_Smell_Tuna
That answered my question, thanks.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.