Well for starters, you don't need to keep typcasting everything. If your function is set up to return a specific item, there's no need to type cast it to that. Example:
Code:
int myfunction( void )
{
int x = 10;
return x; /* Right. */
return (int)x; /* No need to typecast. */
}
Also, you shouldn't typecast malloc, as again, there is no need to do so. If you're getting warnings about it, it's because you're not compiling as C and are instead compiling as C++. (I believe it's covered in the FAQ.)
Anyway... Run this test code, compare it to your own, and find your problem, since you haven't really given us anything to go on:
Code:
#include <stdio.h>
struct quickhack {
int x;
};
struct quickhack *function( int y );
int main( void )
{
struct quickhack *q = NULL;
q = function( 5 );
if( q )
{
printf("q->x = %d\n", q->x );
free( q );
}
return 0;
}
struct quickhack *function( int y )
{
struct quickhack *p = NULL;
p = malloc( sizeof( *p ) );
if( p )
{
p->x = y;
}
return p;
}
Is that what you're trying to do?
Quzah.