Okay, so we had a few problems with a quirky way of getting a value out of a function or method. In C it is common to see something along the lines of:


/* definition of local function n_char */
int something(int* input])
{
   
    *input = 45;
    
    /* return true value  */
    return TRUE;
}

void main()
{
    int n = 0;
    int* addr_n = &n;
    something(addr_n);
    int new_n = n;
       
}

What is happening here is that what is being passed into the method is actually the pointer of the integer n. Inside the 'something' method the pointer is then dereferenced and the contents of the location (not the location itself) are set to 45. 'new_n' is then set to 'n' and thus the value of new_n is set to 45. Its also worth noting that 'TRUE' can be expressed as '1' in C, this is why the int return type from the method here is valid.

Topic revision: r1 - 05 Dec 2008 - 19:02:19 - TrevorFountain
 
This site is powered by the TWiki collaboration platformCopyright © by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback
This Wiki uses Cookies