0

I have three set of array with different data

const UINT16 array1[4] = {1,2,3,4};   

const UINT16 array2[4] = {3,2,2,4};

const UINT16 array3[4] = {8,7,2,4};   //This is not PIN code, :-)

...

void example(void)
{

    UINT16 * pp;

    UINT16 data;

    pp = array1;

    data = pp[0];

    pp = array2;

    data = pp[3];

    pp = array3;

    data = pp[2];

    //and rest of code, this is snipped version of my larger code

}

in dspIC33, I get "warning: assignment discards qualifiers from pointer target type"

Based on impression from google search, I might do this way....

void example(void)
{

    const UINT16 * pp;

    pp = array1;

    pp = array2;

    pp = array3;

    //and rest of code, this is snipped version of my larger code

}

then would that make pp variable that store address data a fixed value? (ie in ROM memory)?

What the right way?, I perfer to keep data in const memory if possible?

1 Answer 1

2

You are wrong in your analysis, pp is not const but the value pointed by pp is const (that is *pp is const).

const UINT16 * pp; // means pp is a pointer to a const UINT16 value

If you want pp to be const as the address pointed is const you have to write:

UINT16 * const pp; // means pp is a const pointer to a UINT16 value

If you want to have both constness of pointer and pointed value, you have to write:

const UINT16 * const pp; // means pp is a const pointer to a const UINT16 value.
Sign up to request clarification or add additional context in comments.

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.