Works also with return values.
Basically you can almost work as in an object oriented approach.

Code:
#include <default.c>


typedef struct spotpoint
{
    int x;
    int y;
    int fn(struct spotpoint * myself, int add_x);    //The function pointer
} SPOT;
int func(SPOT* myself, int add_x)    //your function
{
	int itis=myself->x + add_x;
   return itis;
}

SPOT* setup_spot()  //a init routine
{
    SPOT* spot = malloc(sizeof(SPOT));
    spot->x = 0;
    spot->y = 0;
    spot->fn = func;  //Set fn as func
    return spot;
}

void main()
{
//create the objects
    SPOT* spot = setup_spot();  //create SPOT
    SPOT* spot2 = setup_spot();  //create SPOT
    

//alter attributes in objects    
spot->x=4;		//set values
    spot2->x=3;	//set values
    
//call function in objects, so they work on their personal attributes    
    int whatis= spot->fn(spot,5);   //call func();
    int whatis2= spot2->fn(spot2,5);   //call func();
    
    if(whatis==9) error("Correct value for spot returned!");
    else error("False value spot returned!");
    
    if(whatis2==9) error("Correct value spot2 returned!");
    else error("False value spot2 returned!");
    
}



Last edited by Damocles_; 09/03/10 12:34.