0

received_data is a global char array of length 256. It contains a string at offset rx_pos_p i.e. received_data[rx_pos_p]. I want to return the address of this string through a pointer mem, but I think I am making a mistake. I have written the function as follows:

uint8_t get_bytes(char **mem, uint8_t len){// Be watchful pointer to a pointer
        if(bytes_received() >= len){
            mem = &received_data[rx_pos_p]; //(char *)( received_data + rx_pos_p );

            return 0;
        }
        else
        return FOO;
    }

What should be the type of mem i.e. **mem or *mem ?

2 Answers 2

4

You need to do :

*mem = &received_data[rx_pos_p];

You want to return the pointer in the pointerpointer, so you must dereference it.

Sign up to request clarification or add additional context in comments.

Comments

1

What should be the type of mem i.e. **mem or *mem ?

Since mem is a pointer to a pointer *mem is a pointer to a character (such as the address of the first char of an array)
**mem is a character and is equivalent to (*mem)[0]

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.